Answer the question
In order to leave comments, you need to log in
How to make a selection from SQL most efficient?
It is necessary to solve the problem in SQL as efficiently as possible, which is quite simple.
But so far I can't find an easy way.
Given. 2 tables.
1 table. client id, client request number
2 table. client's request number, date, cost of the order on request
It is necessary to display the amount per month for clients who have more than N orders.
Thank you.
Answer the question
In order to leave comments, you need to log in
If I understand you correctly, then something like this
select
`client`.`id`,
sum(`order`.`price`)
from `order`
join `client` on `order`.`client_id` = `client`.`client_id`
where `order`.`datetime` between "2014-10-01 00:00:00" and "2014-10-31 23:59:59"
group by `client`.`id`
having count(`order`.`id`) > 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question