[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 
 
相关推荐
hairenwangmiao1 小时前
B4041 [GESP202409 四级] 区间排序
算法·排序
minji...2 天前
MySQL数据库 (七) MySQL表的基本查询(上),insert、replace、select、where、order by
数据库·mysql·select·replace·insert·order by·where
csdn_aspnet7 天前
C# list集合 多属性排序
c#·list·linq·排序
8Qi810 天前
LeetCode 75:颜色分类(荷兰国旗问题)—— Java 题解 ✅
java·算法·leetcode·指针·排序
Misnearch10 天前
3635. 最早完成陆地和水上游乐设施的时间II
leetcode·贪心·排序
Dlrb121119 天前
数据结构-单链表与双链表
c语言·数据结构·链表·排序·双链表
郝学胜-神的一滴22 天前
干货版《算法导论》05:从集合接口到排序
开发语言·数据结构·c++·程序人生·算法·排序
汉克老师1 个月前
GESP5级C++考试语法知识(十四、分治算法(一))
算法·归并排序·排序·分治算法·gesp5级·gesp五级
汉克老师1 个月前
GESP2025年3月认证C++五级( 第三部分编程题(1、平均分配))
c++·算法·贪心算法·排序·gesp5级·gesp五级
小书房1 个月前
Kotlin的by
android·开发语言·kotlin·委托·by