Skip to content
Advertisement

How Do You SELECT Both With and Without a WHERE in a Query?

I have a single table, my_table, with data like the following:

I’m trying to write a query that would both sum the number of accesses GROUP BY’d fruit and the total number of access for each fruit, but only the accesses for levels less than 4. A result for that query would be:

I tried the following self join, but didn’t get the expected results:

Is there something that I’m missing? Could this even be done with a self join?

Advertisement

Answer

Use conditional aggregation:

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