Basssque
asked on
querying by the sum of a column in decimal
Can someone tell me how I can only return results when the total of a column is greater than 5 when the values in the column use 2 decimal places?
I have a column called earnedcredits where there may be 9 instances of .33 for a student or 10 instances of .50 for a student. I'd return results for each instance of a total >= 5 and not return anything if < 5
Thanks!!
I have a column called earnedcredits where there may be 9 instances of .33 for a student or 10 instances of .50 for a student. I'd return results for each instance of a total >= 5 and not return anything if < 5
Thanks!!
select * from
(select t.*,sum(earnedcredits) over(partition by student_id) creditsum from your_table)
where creditsum >= 5
(select t.*,sum(earnedcredits) over(partition by student_id) creditsum from your_table)
where creditsum >= 5
OH, now that I see sdstuber's post, I see where the sum comes in.
Ignore my post...
Ignore my post...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
*sigh* yes... I diverted from my original thought and copied someone else's syntax...
ASKER
Worked great, thanks!
I don't understand the two decimal aspect of the requirement.
You mention SUM in the title but the description sounds more like a count.
You can use the group by having to limit only those aggregated values that you want.
If it is a count > 5 then:
select id,count(*) from sometable group by id having count(*) > 5;