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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum data with several grouping levels

Status
Not open for further replies.

thorny00

Programmer
Feb 20, 2003
122
US
I have 3 fields:
dx_cd
person_id
chr_allow_amt

What I need to do is group by dx_cd, then within each dx_cd, group by person_id where the sum of chr_allow_amt is >= $500.00 per person_id within the dx_cd group.

How is something like this done??

There are a great deal more dx_cd values then below. this is a very small sample.
dx_cd person_id chr_allow_amt
0059 uhieXv4hPoeo5Q .0000
0059 uhieXv4hPoeo5Q 375.0000
0059 uWAYXbyT1Gwo5Q 43.2000
0059 uWAYXbyT1Gwo5Q 50.3400
0059 uWAYXbyT1Gwo5Q 97.0600
0059 uWAYXbyT1Gwo5Q 99.8300
0059 uWAYXbyT1tsogh 9.8600
0059 uWAYXbyT1tsogh 97.0600
0059 uWAYXbyT1tsogh 99.8300
00845 igohlboJ1a2hPh .0000
00845 igohlboJ1a2hPh 1684.5500
00845 o5fEFWoqtXOogQ 1166.4200
00845 o5fEFWoqtXOogQ 3133.5800
00845 oQeYXfyolG2o1h .0000
00845 oQeYXfyolG2o1h 3453.6600
00845 Q5AUas0ugFsogQ .0000

For dx_cd 00845, person_id - o5fEFWoqtXOogQ the total would be $4300.00

Thanks for your help and time!!

 
Is this more than:

Code:
select
  dx_cd,
  person_id,
  sum(chr_allow_amount)
from
  myTable
group by
  dx_cd,
  person_id
having
  sum(chr_allow_amount) >= 500.00

?

[tt]|_ |_ _ | _ _
|, | )(/, |(_)| )
'[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top