I just started learning SQL now and trying to figure out this scenario:
We have 3 tables:
- Clients (ClientID, Name, Surname, Age)
- Products (ProductID, Name, Price)
- Purchases (PurchaseID, Date, ClientID, ProductID)
What would be the best SQL query that will show the quantity of purchases (how many products they bought) made by clients?
It must only show the clients who made more than 1 purchase.
The result should contain the following fields:
Full name, Quantity of purchases.
Best Answer
You could do it like this:
DB-Fiddle
As a remark, if
Fullname
orSurname
can beNULL
then you would have to add a check for that, could be done withIFNULL()