I have a problem while regrouping the data from query. I have a dataset like this:
PAT_ID MONTH PRODUCT MOD SEV TOT_CNT
12341 201301 A 1 1 5
12342 201301 B 1 1 5
12343 201301 A 1 0 5
12344 201301 A 0 1 5
I am trying to select like in below query:
select month,product,sum(mod)/tot_cnt as mod_p,sum(sev)/tot_cnt as sev_p from table X group by month, product;
But Its giving output like:
MONTH PRODUCT MOD_P SEV_P
201301 A 0.4 0.4
201301 A 0.4 0.4
201301 A 0.4 0.4
201301 A 0.4 0.4
I want only one row. i.e. 201301 A 0.4 0.4
. I have specified group by clause, but it is not working
You need to distinct your elements like:
select DISTINCT month,product,sum(mod)/tot_cnt as mod_p,sum(sev)/tot_cnt as sev_p
from table X
group by month, product
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments