Reputation: 1
I have this table:
ID Item. Price. Rating Location
-------------------------------------
1 abc 2 xyz
2. milk 10 7
3. rose qqq
4. DVD 10 2
5. WQQ 5
I have to output the result of all the items into good or bad, good item is where Price and Location column is not null or empty.
Output
Good Bad
1 4
How to do that in single query?
Upvotes: 0
Views: 45
Reputation: 7503
Try the following with case
expression. here is the demo.
select
sum(case when price is not null and location is not null then 1 else 0 end) as good,
sum(case when price is null or location is null then 1 else 0 end) as bad
from yourTable
Output:
| good | bad |
| ---- | --- |
| 1 | 4 |
Upvotes: 2