我有一个表如下﹕
派工单号 生产日期 班次 机器号 生产模具 模具号码
1 20051120 A 01101 Y-144 12
1 20051120 A 01102 Y-134 14
1 20051120 A 01103 Y-144 05
1 20051120 A 01104 Y-144 02
1 20051120 A 01105 Y-154 04
1 20051120 A 01201 Y-153 051 20051120 A 01203 Y-123 14
1 20051120 A 01204 Y-128 08
1 20051120 A 01205 Y-123 08
1 20051120 A 02101 Y-134 21
………..
说明 ﹕期中机器号编码为 5码﹐前两码为大机台位 ﹐中间一码表示大机台的前排与后排﹐后两码为生产位﹐生产模具放置处 可不可以用 查询语句转换为下列格式﹕ 将每排的具体模具配置图显示出来
未排定模具的位置显示为空, 有排定模具的将 生产模具 模具号码 两栏合并﹐以’/’相连生产日期 班次 大机台位 生产位1 生产位2 生产位3 生产位4 生产位5
20051120 A 011 y-144/02 Y-134/14 Y-144/05 Y-144/02 Y-154/04
20051120 A 012 Y-153/05 Y-123/14 Y-128/08 Y-123/08
………….
数据库 oracle 8i
派工单号 生产日期 班次 机器号 生产模具 模具号码
1 20051120 A 01101 Y-144 12
1 20051120 A 01102 Y-134 14
1 20051120 A 01103 Y-144 05
1 20051120 A 01104 Y-144 02
1 20051120 A 01105 Y-154 04
1 20051120 A 01201 Y-153 051 20051120 A 01203 Y-123 14
1 20051120 A 01204 Y-128 08
1 20051120 A 01205 Y-123 08
1 20051120 A 02101 Y-134 21
………..
说明 ﹕期中机器号编码为 5码﹐前两码为大机台位 ﹐中间一码表示大机台的前排与后排﹐后两码为生产位﹐生产模具放置处 可不可以用 查询语句转换为下列格式﹕ 将每排的具体模具配置图显示出来
未排定模具的位置显示为空, 有排定模具的将 生产模具 模具号码 两栏合并﹐以’/’相连生产日期 班次 大机台位 生产位1 生产位2 生产位3 生产位4 生产位5
20051120 A 011 y-144/02 Y-134/14 Y-144/05 Y-144/02 Y-154/04
20051120 A 012 Y-153/05 Y-123/14 Y-128/08 Y-123/08
………….
数据库 oracle 8i
生产日期,
班次,
substr(机器号,1,2) as 机器号,
max(decode(substr(机器号,4,2),'01',生产模具||'/'||模具号码)) as 生产位1,
max(decode(substr(机器号,4,2),'02',生产模具||'/'||模具号码)) as 生产位2,
max(decode(substr(机器号,4,2),'03',生产模具||'/'||模具号码)) as 生产位3,
max(decode(substr(机器号,4,2),'04',生产模具||'/'||模具号码)) as 生产位4,
max(decode(substr(机器号,4,2),'05',生产模具||'/'||模具号码)) as 生产位5
from
表
group by
生产日期,班次,substr(机器号,1,2)
order by
生产日期,班次,substr(机器号,1,2)
生产日期,
班次,
substr(机器号,0,2) as 机器号,
max(decode(substr(机器号,3,2),'01',生产模具||'/'||模具号码)) as 生产位1,
max(decode(substr(机器号,3,2),'02',生产模具||'/'||模具号码)) as 生产位2,
max(decode(substr(机器号,3,2),'03',生产模具||'/'||模具号码)) as 生产位3,
max(decode(substr(机器号,3,2),'04',生产模具||'/'||模具号码)) as 生产位4,
max(decode(substr(机器号,3,2),'05',生产模具||'/'||模具号码)) as 生产位5
from
表
group by
生产日期,班次,substr(机器号,0,2)
order by
生产日期,班次,substr(机器号,0,2)
----------------------------------------------------------------------------------------------
select
生产日期,
班次,
substr(机器号,0,3) as 机器号,
max(decode(substr(机器号,3,2),'01',生产模具||'/'||模具号码)) as 生产位1,
max(decode(substr(机器号,3,2),'02',生产模具||'/'||模具号码)) as 生产位2,
max(decode(substr(机器号,3,2),'03',生产模具||'/'||模具号码)) as 生产位3,
max(decode(substr(机器号,3,2),'04',生产模具||'/'||模具号码)) as 生产位4,
max(decode(substr(机器号,3,2),'05',生产模具||'/'||模具号码)) as 生产位5
from
表
group by
生产日期,班次,substr(机器号,0,3)
order by
生产日期,班次,substr(机器号,0,3)
生产日期,
班次,
substr(机器号,0,2)+decode(substr(机器号,2,1),'1','前','2','后') as 机器号,
max(decode(substr(机器号,3,2),'01',生产模具||'/'||模具号码)) as 生产位1,
max(decode(substr(机器号,3,2),'02',生产模具||'/'||模具号码)) as 生产位2,
max(decode(substr(机器号,3,2),'03',生产模具||'/'||模具号码)) as 生产位3,
max(decode(substr(机器号,3,2),'04',生产模具||'/'||模具号码)) as 生产位4,
max(decode(substr(机器号,3,2),'05',生产模具||'/'||模具号码)) as 生产位5
from
表
group by
生产日期,班次,substr(机器号,0,2)+decode(substr(机器号,2,1),'1','前','2','后')
order by
生产日期,班次,substr(机器号,0,2)+decode(substr(机器号,2,1),'1','前','2','后')