1

I have a table like this:

enter image description here

Each keyword should have 4 pieces of data.

I want to select the keywords that have less than 4 pieces of data (less than 4 rows).

I used select count(*) from mytable group by keyword to achieve something like this:

enter image description here

how can I select the keywords based on the count(*) result?

Here I want the keyword b from the result grid.

1 Answer 1

2

You can either nest your select and use a where clause in the outer select:

select keyword 
from (
    select keyword, count(*) as cnt
    from mytable
    group by keyword
) as t
where cnt < 4

or you can use having which essentially is a shorter form of the above:

select keyword
from mytable
group by keyword
having count(*) < 4
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.