how can i count all rows approved in sql?

You can use group by and having:

select color, count(*) cnt
from mytable
group by color
having min(status) = max(status) and min(status) = 'approved'

The having clause ensures that there is only one distinct value in the group, whose value is 'approved'.

In MySQ, you could also phrase the having clause like so:

having max(status <> 'approved') = 0

Or simply:

having not max(status <> 'approved')

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top