테이블 A
Orderno | Code | Item | SubItem | cQty | cPrice | cAmt | Yyyy |
17A527 | M-010 | 46-549 | ORDER 355NM | 1 | 473111 | 473111 | 2017 |
17A527 | M-1037 | ss-YT10 | sd-52 | 1 | 13000000 | 13000000 | 2017 |
17A527 | M-109 | 202-A-H-750 | FORCER | 1 | 603564 | 603564 | 2017 |
17A527 | M-1217 | CT-4500-66 | CABLE | 1 | 37647 | 37647 | 2017 |
19A119 | M-13685 | LASER | 355-20 NL | 1 | 26191801 | 26191801 | 2022 |
19D001 | M-10180 | SO_14 | A6061 | 1 | 40000 | 40000 | 2019 |
19D001 | M-10181 | Z-AXIS | A6061 | 1 | 39000 | 39000 | 2019 |
테이블 A 를 이런식으로 표현이 가능할까요?
Code | Item | SubItem | cQty | cPrice | cAmt | Yyyy |
17A527 | 14114322 | |||||
M-010 | 46-549 | ORDER 355NM | 1 | 473111 | 473111 | 2017 |
M-1037 | ss-YT10 | sd-52 | 1 | 13000000 | 13000000 | 2017 |
M-109 | 202-A-H-750 | FORCER | 1 | 603564 | 603564 | 2017 |
M-1217 | CT-4500-66 | CABLE | 1 | 37647 | 37647 | 2017 |
19A119 | 26191801 | |||||
M-13685 | LASER | 355-20 NL | 1 | 26191801 | 26191801 | 2022 |
19D001 | 79000 | |||||
M-10180 | SO_14 | A6061 | 1 | 40000 | 40000 | 2019 |
M-10181 | Z-AXIS | A6061 | 1 | 39000 | 39000 | 2019 |
대략 이런 식을껀데요. 참고요..
with tmp as
(select '17A527' as Orderno, 'M-010' as Item, '46-549 ORDER 355NM' as SubItem, 1 as cQty, 473111 as cPrice, 473111 as cAmt, 2017 as Yyyy union all
select '17A527','M-1037','ss-YT10 sd-52', 1,13000000,13000000,2017 union all
select '17A527','M-109','202-A-H-75 FORCER',1,603564,603564,2017 union all
select '17A527','M-1217','CT-4500-66 CABLE',1,37647,37647,2017 union all
select '19A119','M-13685','LASER 355-20 NL',1,26191801,26191801,2022 union all
select '19D001','M-10180','SO_14 A6061',1,40000,40000,2019 union all
select '19D001','M-10181','Z-AXIS A6061',1,39000,39000,2019)
select *
from (
select
Orderno, item, subitem, sum(cQty) as cQty, sum(cPrice) as cPrice, sum(cAmt) as cAmt, Yyyy
from tmp
group by Orderno, item, subitem, Yyyy
with rollup
) x
where
(orderno is not null and
item is not null and
subitem is not null and
yyyy is not null
) or
(orderno is not null and
item is null and
subitem is null and
yyyy is null
)
order by orderno, item