Skip to content
Advertisement

How to use conditions with a RANK statement

The following piece of code does its job : it gives me the top 10 results for each category.

Now I’d like to add conditions so that the number of results may vary based on a criteria. Example : if “note” = 1, then I want to retain 1 result, else make it 3.

I tried something along the lines which you can see below using the CASE WHEN statement but as you might expect it doesn’t work. Error returned :

1 – near “CASE”: syntax error

Do you have any ideas how to make this work? My knowledge of SQL is pretty limited. The code has to be SQLite/SpatiaLite compatible as I’m working in the QGIS environment. Thanks.

Advertisement

Answer

You can use boolean logic in the WHERE clause of the outer query:

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