Oracle SQL - 在组内重复相同的列值
我需要一些帮助来调整以下查询
select
data.smalldate,
mip.mip_step_description,
error_code.error_code_en,
count(case when (error_code is null and quality_plan is null) then data.part_serial_number end) as "Input",
count(case when error_code is not null then data.part_serial_number end) as "Defects"
from Data
left join MIP
On data.equipment = mip.equipment
left join error_code
on data.error_code = error_code.error_code_sn
group by data.smalldate, mip.mip_step_description, error_code.error_code_en
order by data.smalldate, mip.mip_step_description, count(data.part_serial_number) desc
正如您在 select 语句中所看到的,我在计数函数中使用了 case 语句。这很好用。数据输出看起来像这样,
Date MIP_Desc Error_Code Input Defects
1/1/2011 MIP Z (null) 100 0
1/1/2011 MIP Z A 0 10
1/1/2011 MIP Z B 0 15
我想在具有相同日期和 MIP_Desc 的所有行的输入列中填写相同的输入值。
输出应该是这样的
Date MIP_Desc Error_Code Input Defects
1/1/2011 MIP Z (null) 100 0
1/1/2011 MIP Z A 100 10
1/1/2011 MIP Z B 100 15
I'd like some help tweaking the following query
select
data.smalldate,
mip.mip_step_description,
error_code.error_code_en,
count(case when (error_code is null and quality_plan is null) then data.part_serial_number end) as "Input",
count(case when error_code is not null then data.part_serial_number end) as "Defects"
from Data
left join MIP
On data.equipment = mip.equipment
left join error_code
on data.error_code = error_code.error_code_sn
group by data.smalldate, mip.mip_step_description, error_code.error_code_en
order by data.smalldate, mip.mip_step_description, count(data.part_serial_number) desc
As you can see in the select statement, I'm using case statements within my count functions. This works fine. Data output looks like this
Date MIP_Desc Error_Code Input Defects
1/1/2011 MIP Z (null) 100 0
1/1/2011 MIP Z A 0 10
1/1/2011 MIP Z B 0 15
I'd like to fill in the same input value in the input column throughout all the rows that have the same date and MIP_Desc.
Output should look like this
Date MIP_Desc Error_Code Input Defects
1/1/2011 MIP Z (null) 100 0
1/1/2011 MIP Z A 100 10
1/1/2011 MIP Z B 100 15
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有帮助吗? (未经测试):
Does this help? (untested):