Suppose I have a table with 2 columns (status and date) like the following:
status: U T U U L
date: 12 14 15 16 17
Can I (using only 1 SQL statement) count the number of distinct values in the status? That is:
- count(U)=3
- count(T)=1
- count(L)=2
- count(P)=0
Can I do this with 1 SQL query?
Note: I have static values in status. I can only have (U-T-L-P)
This will return a row for every
statusand the count in the second column:So it would return
for your example (in no defined order). Use
ORDER BYif you want to sort the results.