Hello,
Would anybody know if this is possible at all? Preferably within the function without further grouping or nesting as this is a much simpified explanation of an issue I am having with a far larger and more esoteric query...
If I have a table with ID codes in column A, which are often repeated over several rows, and USD amounts in column A.
eg.
ID¦USD
1¦1,000
2¦5,000
3¦2,000
3¦2,000
3¦2,000
3¦2,000
4¦5,000
4¦5,000
5¦20,000
5¦20,000
5¦20,000
I would like to sum the USD amount in column B, but only once per unique ID in column A, ie (1000+5000+2000+5000+20000 = 33000)
I tried the following syntax to no avail;
sum(USD) over(distinct ID) ob
I am assuming that the following would count each distinct USD amount, this is not what I am looking for;
sum(distinct USD) ob
FYI here is the query shell that I am trying to use this in, the problem I have is that the ID codes in the query results i've called 'table' duplicate (correctly) IDs on occassion, I only want my counts and sums to count each ID once though. I can easily count my distinct IDs but I am not sure how get it to sum the values in the other columns based on this.
select geo_segment_name
, bus_grp_typ
, agg_grp_sctr
, sum(original_balance_usdm) ob --need this for distict class_ids
, sum(current_balance_qport_usdm) cb --need this for distict class_ids
, count(distinct deal_id) deal_count
, count(distinct class_id) class_count
from (table)
group by geo_segment_name, bus_grp_typ, agg_grp_sctr
Could anyone please advise?
In your debt!
Thanks
Jon