Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub-totals with group by

Status
Not open for further replies.

AIXFinder

IS-IT--Management
Jan 4, 2007
97
US
I have this query and the output:

select
ptloc, RMOutcomeAct, RMOutcomePot,
count (RMOutcomeAct) as ActCount,
count (RMOutcomePot) as PotCount,
sum(RxDoseAct) as ActSUM,
sum(RxDosePot) as PotSUM
from Report r, RMInvest m, PharmInvest p, AdminInvest a
where r.ReportNo = m.RMReportNo and m.RMReportNo = p.RxReportNo
and p.RxReportNo = a.ReportNo and convert (datetime, NurDateofOcc) between '01/01/2006' and '12/31/2006'
group by ptloc, RMOutcomeAct, RMOutcomePot
order by ptloc, RMOutcomeAct

but, I want the sub-total of sum(RxDoseAct) = ActSUM and sum(RxDosePot) = PotSUM per "Location", which is ptloc.

i.e.

The output gives:

ptloc .... ActSum ... PotSUM ...
2N 11 7
2N 17 19
2N 9 12
2S 5 3
2S 6 4

bla.....

What I want is:

ptloc .... ActSum ... PotSUM ...
2N 11 7
2N 17 19
2N 9 12
Sub-total for 2N 37 38
2S 5 3
2S 6 4
Sub-total for 2S 11 7
bla...


I want all of the columns from the existing query, and, on the top of those, I want the two sub-totals per ptloc like above.

thx much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top