报错

image.png

select t1.* 

from(

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag,

qty_time1 as "实际产出"

,case when shifts_team = '白班' then '09:30' else '21:30' end as "时间点"

,9 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time2 as "产量"

,case when shifts_team = '白班' then '10:30' else '22:30' end as "时间点"

,10 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time3 as "产量"

,case when shifts_team = '白班' then '11:30' else '23:30' end as "时间点"

,11 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time4 as "产量"

,case when shifts_team = '白班' then '12:30' else '00:30' end as "时间点"

,12 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time5 as "产量"

,case when shifts_team = '白班' then '13:30' else '01:30' end as "时间点"

,13 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time6 as "产量"

,case when shifts_team = '白班' then '14:30' else '02:30' end as "时间点"

,14 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time7 as "产量"

,case when shifts_team = '白班' then '15:30' else '03:30' end as "时间点"

,15 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time8 as "产量"

,case when shifts_team = '白班' then '16:30' else '04:30' end as "时间点"

,16 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time9 as "产量"

,case when shifts_team = '白班' then '17:30' else '05:30' end as "时间点"

,17 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time10 as "产量"

,case when shifts_team = '白班' then '18:30' else '06:30' end as "时间点"

,18 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time11 as "产量"

,case when shifts_team = '白班' then '19:30' else '07:30' end as "时间点"

,19 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

union all

select 

workcell_name, equip_name, equipment_id, operation_desc, shifts_team, qty_flag, 

qty_time12 as "实际产出"

,case when shifts_team = '白班' then '20:30' else '08:30' end as "时间点"

,20 as num

from ads.calb_output_report_equip_one_hour_v

where base_flag = 'XM'

and area_type NOT IN ('模组','模组段','PACK')

and qty_flag = '每小时'

and factory_stage = 'XMA1'

and prod_line_code like 'C1%'

and operation_desc = '切叠'

and partion_by = '2022-07-20'

and shifts_team = '白班'

order by equipment_id

)t1

order by num, equipment_id

SQL 帆软用户YbG5J0kkjo 发布于 2023-7-11 09:22
1min目标场景问卷 立即参与
回答问题
悬赏:0 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2023-7-11 09:24

union 前后的sql 里面的 排序全删了

  • 帆软用户YbG5J0kkjo 帆软用户YbG5J0kkjo(提问者) order by num, equipment_id最后这条删吗
    2023-07-11 09:40 
  • Z4u3z1 Z4u3z1 回复 帆软用户YbG5J0kkjo(提问者) 所有的。 union 连接的SQL不能排序。要排序只能在外面嵌套一层SELECT .比如:select * from ( sql1 union sql2) a order by xxxx
    2023-07-11 09:42 
  • 帆软用户YbG5J0kkjo 帆软用户YbG5J0kkjo(提问者) 回复 Z4u3z1 好的,那在外面可以这样定义字段名称吗t2.\"计划产出\" as \"计划产出\"
    2023-07-11 09:47 
  • Z4u3z1 Z4u3z1 回复 帆软用户YbG5J0kkjo(提问者) 外面可以的。里面的第一条sql上重命名也可以。一试便知不用问的
    2023-07-11 09:51 
  • 1关注人数
  • 214浏览人数
  • 最后回答于:2023-7-11 09:24
    请选择关闭问题的原因
    确定 取消
    返回顶部