Skip to content
Advertisement

Query for selecting all customers with the total number of orders in a specific range [closed]

As the title says, I want to select all customers with the total number of orders in a specific range, I came up with the following SQL query :

I want to know if this is the proper way to do it.

Is there any better way to write this query? Do I need to use always sub-query for this task?

Advertisement

Answer

Try this, you can get rid of the where clause:

or another version, depending on your preference:

To also select order.ids:

or a different version:

Using exists:

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