sql - 根据特定材料从同一列中选择每第 2、第 4 行等
问题描述
在 1 个包装中得到 2 个材料,项目序列为 00010 和 00020。我需要的是,如果我在 where 语句中输入 00010 的材料,即“CB016”,我可以列出所有项目序列 00020。
表数据
Packing ItemSeq ItemCate Material TargetQty MinQty
1000009654 10 P CB016 1 0
1000009654 20 I 10000015991 48 0
1000012548 10 P CB016 1 0
1000012548 20 I 10000009495 48 0
1000012564 10 P CB016 1 0
1000012564 20 I 10000009517 48 0
1000007961 10 P CB017 1 0
1000007961 20 I 10000003423 10000 0
1000007962 10 P CB017 1 0
1000007962 20 I 10000003424 10000 0
预期产出
Packing ItemSeq ItemCate Material TargetQty MinQty
1000009654 20 I 10000015991 48 0
1000012548 20 I 10000009495 48 0
1000012564 20 I 10000009517 48 0
解决方案
您可以尝试使用 row_number() 函数:
select * from
(select *, row_number() over (partition by packing order by itemseq desc) as rn)a
where rn=1
推荐阅读
- node.js - VPSServer:无法在浏览器中识别域名
- python - PyQt5 - QFrame 大小在窗口中被忽略
- solr - Pysolr add throws (HTTP 500): [原因:任务队列处理已停止
- python - Docker / Python / LibreOffice:[Java 框架] 函数 createSettingsDocument (elements.cxx) 中的错误。javaldx 失败
- ios - 安装了 Appsflyer SDK,仍然收到未安装 SDK 的邮件
- python - 无法从 Yelp 中提取评论
- android - 德尔福 FMX 安卓汽车服务
- android - Android 在方向更改时崩溃
- javascript - Angular routerLink 附加路由而不是替换
- amazon-web-services - 如何使用 SecureString SSM 参数存储创建 EC2 实例?