Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>declare @datebegin datetime declare @dateend datetime set @datebegin = '09/04/2012' set @dateend = '09/08/2012' select machines.serialnum, DRPS.MOCALCSUM,DRPS.MICALCSUM,DRPS.COCALCSUM,DRPS.CICALCSUM,ISSUED.TotalIssued, REDEEMED.TotalRedeemed,drps.dropdate1,drps.dropdate2 from (select serialnum from machineinfo) as machines LEFT JOIN (select assetnumber,min(dropdate)as [dropdate1], max(dropdate)as [dropdate2], sum(mocalc) AS [MOCALCSUM],sum(micalc) AS [MICALCSUM], sum(cocalc) AS [COCALCSUM],sum(cicalc) AS [CICALCSUM] from drops where dropdate &gt; @datebegin and dropdate &lt; @dateend AND (ignore is null) group by assetnumber) AS DRPS on machines.serialnum = drps.assetnumber LEFT JOIN (select snissued,cast(sum(amount)as money)/100 AS [TotalIssued] from tickets where (dateissued &gt; (select min(dropdate) from drops where dropdate &gt; @datebegin AND (ignore is null) and snissued = assetnumber )) and (dateissued &lt; (select max(dropdate) from drops where dropdate &lt; @dateend AND (ignore is null) and snissued = assetnumber)) group by snissued) AS ISSUED ON machines.serialnum=ISSUED.snissued LEFT JOIN (select snredeemed,cast(sum(amount)as money)/100 AS [TotalRedeemed] from tickets where (dateredeemed &gt; (select min(dropdate) from drops where dropdate &gt; @datebegin AND (ignore is null)and snissued = assetnumber)) and (dateredeemed &lt; (select max(dropdate) from drops where dropdate &lt; @dateend AND (ignore is null)and snissued = assetnumber )) group by snredeemed) AS REDEEMED ON machines.serialnum=REDEEMED.snredeemed order by REDEEMED.TotalRedeemed desc </code></pre> <p>based on the suggestion from comments i added the subquery into the selects and i am getting expected results now</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload