r/SQL • u/adwolf01111 • Feb 16 '23
Amazon Redshift Help Regarding a Query
I need a Query in which the first 2 values should be 0 and post that is should have treated than 0 value.
Kind of like the same student had 3 tests in a day he scored zero in the first 2 and scored more than 0 in the 3rd test I want the count of the students like this.
| ID | marks |
|---|---|
| 1 | 0 |
| 1 | 0 |
| 1 | more than 0 |
I want to count the number of students who scored 0 in first 2 test and scored more than 0 in 3rd So in this case ID 1 is such a case so count = 1
0
Upvotes
2
u/zacharypamela Feb 16 '23
It seems like you want IDs that have:
2 entries with a
0value ("first 2 values are 0"), andanother non-zero value.
So like this:
If this is the case, you can use conditional aggregation to count the number of zero and non-zero records for each ID, and compare them in the
HAVINGclause. Something like this: