Skip to content
Advertisement

Is it possible to COUNT if one value occured more than the other value in a column using SQL

I have this table called task_status which has the following structure:

and a status_list table that has the possible statuses available

Now what I want to do is check which number occurred more inside the status_id column 1 occurred more, 2 occurred more or 3 occurred more? using SQL.

Is it possible to do and if so how to?

Advertisement

Answer

You can count the column first then filter with max
there is a lot of different way to do this but i prefer using cte. Here is a example :

also here is db<>fiddle for better examine.
I modify some data to show the much more understandable output. But idea is same.

also I don’t really think status table have any work doing here, but remind me if I misunderstand what you mean.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement