I have a table orders(c_id(INT),o_date(DATE),o_price(INT)). I have to find out the id and MAX value of total price for each id in the current year. The table is as follows:
c_id o_date o_price
1 2017-08-27 30
2 2017-05-25 100
2 2017-05-02 20
1 2017-02-23 80
3 2017-01-26 60
4 2016-04-22 10
2 2016-03-15 5
1 2015-09-01 1
I code as follow:
SELECT c_id, MAX(m_price)
FROM ( SELECT c_id, SUM(o_price) AS
m_price FROM orders WHERE
( YEAR(o_date) = YEAR(curdate()) )
GROUP
> BY c_id )AS T
the MAX value return right but the id is not fit with that MAX value. Has anyone a suggestion for my situation? Thank you in advance!!