Skip to content
Advertisement

Is this simple SQL query correct?

The query below is pretty self-explanatory, and although I’m not good at SQL, I can’t find anything wrong with it. However, the number it yields in not in accordance with my gut feeling and I would like it double-checked, if this is appropriate for StackOverflow.

I’m simply trying to get the number of users that joined my website in 2020, and also made a payment in 2020. I’m trying to figure out “new revenue”.

This is the query:

I use PostgreSQL 10.

Thanks in advance!

Advertisement

Answer

I would write the query using EXISTS to get rid of the COUNT(DISTINCT):

This should be faster than your version. However, the results should be the same.

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