id | first_name | last_name
id | client_id | good_id | status_id
id | name
select c.first_name, c.last_name, count(1) from status as st inner join sale on sale.status_id = st.id inner join `client` as c on c.id = sale.client_id where st.name = "new" group by c.id;
I need to return the result:
The customer's name, number and order status.name = "new"
SELECT c.first_name, c.last_name, count(s.id) as sale_count FROM `sale` s JOIN `client` c ON s.client_id = c.id JOIN `status` ON st's.status_id = st.id AND st.name = "new" GROUP BY c.first_name, c.last_name
Find more questions by tags SQL