[MySQL]order by失效

失效语句:

获取的change_date不是最大值

sql 复制代码
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生效

sql 复制代码
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 
 
相关推荐
汉克老师15 小时前
GESP2026年6月认证C++八级( 第三部分编程题(1、线网建设))精讲
c++·最小生成树·排序·kruskal·并查集·gesp8级
Tisfy2 天前
LeetCode 1288.删除被覆盖区间:排序(非二重循环暴力)
算法·leetcode·题解·排序
hairenwangmiao1 个月前
c++排序(第一章----桶排序与sort排序)
数据结构·c++·排序
hairenwangmiao1 个月前
B4041 [GESP202409 四级] 区间排序
算法·排序
minji...1 个月前
MySQL数据库 (七) MySQL表的基本查询(上),insert、replace、select、where、order by
数据库·mysql·select·replace·insert·order by·where
csdn_aspnet1 个月前
C# list集合 多属性排序
c#·list·linq·排序
8Qi81 个月前
LeetCode 75:颜色分类(荷兰国旗问题)—— Java 题解 ✅
java·算法·leetcode·指针·排序
Misnearch1 个月前
3635. 最早完成陆地和水上游乐设施的时间II
leetcode·贪心·排序
Dlrb12112 个月前
数据结构-单链表与双链表
c语言·数据结构·链表·排序·双链表
郝学胜-神的一滴2 个月前
干货版《算法导论》05:从集合接口到排序
开发语言·数据结构·c++·程序人生·算法·排序