求一段sql

_小黑_ 2019-02-13 11:12:08

year month channel product week qty datatype qtytype date
2018 5 Chain and Dept. Store 02233710 18 0 Display_Inv Actual 2019-02-13 10:49:40.773
2018 5 Chain and Dept. Store 02233710 19 0 Display_Inv Actual 2019-02-13 10:49:40.773
2018 5 Chain and Dept. Store 02233710 21 0 Display_Inv Actual 2019-02-13 10:49:40.773
2018 5 Chain and Dept. Store 02439713 18 0 Display_Inv Actual 2019-02-13 10:49:40.773
2018 5 Chain and Dept. Store 02439713 21 0 Display_Inv Actual 2019-02-13 10:49:40.773
--以上是数据表
--以下是想要的结果
year month channel product week qty datatype qtytype date
2018 5 Chain and Dept. Store 02233710 21 0 Display_Inv Actual 2019-02-13 10:49:40.773
2018 5 Chain and Dept. Store 02439713 21 0 Display_Inv Actual 2019-02-13 10:49:40.773
求一段sql
...全文
99 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2019-02-13
  • 打赏
  • 举报
回复
e.g.
SELECT *
FROM
(SELECT *
,ROW_NUMBER() OVER (PARTITION BY year, month, channel, product ORDER BY week DESC) AS RN
FROM tab) AS T
WHERE RN=1
唐诗三百首 2019-02-13
  • 打赏
  • 举报
回复

select *
from [表名] a
where not exists(select 1
from [表名] b
where b.year=a.year
and b.month=a.month
and b.channel=a.channel
and b.product=a.product
and b.week>a.week)

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧