I have a table with multiple columns:
table1 | column1 | column2 | column3 |
| x | .... | .... |
| y | .... | .... |
| x | .... | .... |
How can I count the occurences of a value, for example x, in one of the columns, for example column1? Given table1 this would have to return me 2 (numbers of x present in column1).
You can use SUM()
aggregate function with a CASE
statement like
select sum(case when column1 = 'x' then 1 else 0 end) as X_Count
from tabl1;
SELECT COUNT(*) FROM table1 WHERE column1 = 'x'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With