求分组sql

jianglai11 jianglai11 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

create table tb(price DECIMAL(18,2), RecordDate DATETIME)

--临时数据
insert into tb
select 1.23000,'2013-04-24 00:00:00'
union all select 1.25000, '2013-04-25 00:00:00'
union all select 1.25000 ,'2013-04-25 00:00:00'
union all select 1.25000 ,'2013-04-25 00:00:00'
union all select 1.25000 ,'2013-04-26 00:00:00'
union all select 1.28000 ,'2013-04-26 00:00:00'
union all select 1.25000 ,'2013-04-27 00:00:00'
union all select 1.25000 ,'2013-05-06 00:00:00'
union all select 1.24000 ,'2013-05-06 00:00:00'
union all select 1.24000 ,'2013-05-12 00:00:00'
union all select 1.24000 ,'2013-05-12 00:00:00'
union all select 1.24000 ,'2013-05-12 00:00:00'
union all select 1.30000 ,'2013-10-26 00:00:00'
union all select 1.31000 ,'2013-10-26 00:00:00'

SELECT * FROM tb
--求价格变化趋势Sql,并记录变化的日期,
--如果同一日期则记录最大值,
--记录变化日期的最早日期,
--如4-27和5-6同价则记录4-27
--期望结果如下:
--1.23 2013-04-24 00:00:00.000
--1.25 2013-04-25 00:00:00.000
--1.28 2013-04-26 00:00:00.000
--1.25 2013-04-27 00:00:00.000
--1.24 2013-05-06 00:00:00.000
--1.31 2013-10-26 00:00:00.000
...全文
评论 8
收藏 已收藏
分享
返回顶部
jianglai11
MS-SQL Server 34,876 成员 254,635 内容