F
F
FilatovNikita2018-04-16 22:43:24
MySQL
FilatovNikita, 2018-04-16 22:43:24

How to organize a complex query?

There are 2 tables clients and orders, you need to make a query that will display the name and id of the client, whose number of applications is more than 3. The difficulty is that in orders each order has an id_clients field and these id_clients are repeated, you must first calculate how many repeated id_clients and display only those who have more than 3 repetitions.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bioGavs, 2018-04-16
@FilatovNikita

More or less like this

SELECT c.id, c.name FROM orders AS o INNER JOIN clients c ON o.id_client=c.id GROUP BY o.id_client HAVING count(o.id_client) > 3

T
twobomb, 2018-04-16
@twobomb

SELECT clients.name,clients.id FROM clients WHERE (SELECT COUNT(*) FROM orders WHERE orders.id_client = clients.id) >3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question