oracle - 创建 Oracle 数据库查询
问题描述
我有下表(tb1):
我需要创建一个包含以下内容的查询:
- 选择状态为 001 的最早的 Date_created。
- 如果同一 PCR 的状态为 002,则不应选择 PCR。
对于上表,此查询应返回下表:
谁能帮助我如何创建它?
解决方案
最终查询:select q2.id,q2.PCR,q2.status, q2.date_created from (select pcr, min(date_created) date_created from table1 t1 where not exists (select * from table1 t2 where t1.pcr = t2.pcr and t2.status = '002') group by pcr) q1 inner join (select * from table1) q2 on q1.PCR = q2.PCR and q1.date_created = q2.date_created
推荐阅读
- angularjs - 将日期与最小值和最大值进行比较不起作用
- c# - XAML - PostAsync 将空数据发送到数据库
- prestashop - 在移动设备中查看 prestashop 页面时,如何用 html 数据填充 _mobile_* div
- memory-leaks - 这段代码对内存泄漏安全吗
- jmeter - 使用 Jmeter,如果用户在第一次执行时已经存在,我们如何使用 CSV 文件创建用户
- r - 如何加快我的逻辑回归自举 R 函数?
- powershell - 在 Powershell 中添加到通配符数组
- javascript - 在图标单击时显示 javascript datepicker
- unity3d - 应用更新后 Unity WebGL 保持本地数据
- jquery - 使用 jQuery 的 HTML 表格中的百分比份额(新行)