[mysql]order by失效_balmunc的博客-爱代码爱编程
失效语句:
获取的change_date不是最大值
select product_id, new_price, change_date
from (
select product_id ,new_price, change_date
from Products
order by change_date desc
) as a
group by product_id
生效语句:
增加distinct使order by生效
select product_id, new_price, change_date
from (
select distinct(product_id) product_id, new_price, change_date
from Products
order by change_date desc
) as a
group by product_id