프로그램에서 하던 원장을 쿼리문으로 바꾸려 합니다.
데이터베이스 작업을 한지가 오래되서 구현이 잘 안되네요.
정중히 도움을 청합니다.
사용 환경 : 오라클11g, 12c/ SQL SERVER 2016, 2017
(SELECT 'QT06' rawcod,'20141111' iodate,'I' io,05 seq,'N' iotype,'003' vendcd,'AM19' grade,'01' colorcd,'1429207' lotno,475 pur_qty,0 out_qty,'2014-11-20 12:28:50' cre_date FROM DUAL UNION ALL
SELECT 'QT01', '20141114', 'I', 01, 'N', '002', 'AM03', '01', '4H72U', 1000, 0, '2014-11-20 12:04:33' FROM DUAL UNION ALL
SELECT 'QT01', '20141119', 'I', 07, 'N', '002', 'AM05', '01', '4J9030U', 200, 0, '2014-11-20 12:30:36' FROM DUAL UNION ALL
SELECT 'QT01', '20141119', 'I', 04, 'N', '002', 'AM04', '01', '4F3022U', 500, 0, '2014-11-20 12:28:02' FROM DUAL UNION ALL
SELECT 'QT01', '20141121', 'I', 09, 'N', '002', 'AM02', '01', '4K6020U', 825, 0, '2014-11-26 14:21:20' FROM DUAL UNION ALL
SELECT 'QT06', '20141125', 'I', 10, 'N', '003', 'AM20', '01', '1428707', 850, 0, '2014-11-26 14:22:21' FROM DUAL UNION ALL
SELECT 'QT01', '20141126', 'I', 13, 'N', '002', 'AM02', '01', '4K6020U', 1000, 0, '2014-11-26 14:42:41' FROM DUAL UNION ALL
SELECT 'QT01', '20141126', 'I', 12, 'N', '002', 'AM03', '01', '4111P', 1000, 0, '2014-11-26 14:23:15' FROM DUAL UNION ALL
SELECT 'QT01', '20141126', 'I', 11, 'N', '002', 'AM03', '01', '4G30U', 1000, 0, '2014-11-26 14:22:51' FROM DUAL UNION ALL
SELECT 'QT01', '20141128', 'I', 16, 'N', '002', 'AM03', '01', '4H27U', 1000, 0, '2014-11-28 09:17:06' FROM DUAL UNION ALL
SELECT 'QT01', '20141128', 'I', 15, 'N', '002', 'AM02', '01', '4J6021U', 1000, 0, '2014-11-28 09:16:36' FROM DUAL UNION ALL
SELECT 'QT06', '20141128', 'I', 14, 'N', '003', 'AM19', '01', '1431907', 1000, 0, '2014-11-28 09:15:56' FROM DUAL UNION ALL
SELECT 'QT01', '20150102', 'I', 17, 'N', '002', 'AM03', '01', '4L28U', 75, 0, '2015-01-08 14:30:02' FROM DUAL UNION ALL
SELECT 'QT02', '20150106', 'I', 24, 'N', '002', 'AM05', '01', '4K9022U', 75, 0, '2015-01-08 14:36:02' FROM DUAL UNION ALL
SELECT 'QT02', '20150106', 'I', 23, 'N', '002', 'AC06', '01', '4I9011U', 200, 0, '2015-01-08 14:34:49' FROM DUAL UNION ALL
SELECT 'QT06', '20150106', 'I', 22, 'N', '003', 'AM20', '01', '1428707', 200, 0, '2015-01-08 14:33:55' FROM DUAL UNION ALL
SELECT 'QT05', '20150106', 'I', 21, 'N', '003', 'AM12', '01', '14340B1', 175, 0, '2015-01-08 14:33:18' FROM DUAL UNION ALL
SELECT 'QT06', '20150106', 'I', 20, 'N', '003', 'AM19', '01', '1435607', 500, 0, '2015-01-08 14:32:35' FROM DUAL UNION ALL
SELECT 'QT01', '20150106', 'I', 19, 'N', '002', 'AM02', '01', '4L4122U', 750, 0, '2015-01-08 14:31:43' FROM DUAL UNION ALL
SELECT 'QT01', '20150106', 'I', 18, 'N', '002', 'AM03', '01', '4L02P', 1200, 0, '2015-01-08 14:31:05' FROM DUAL UNION ALL
SELECT 'QT02', '20150210', 'I', 30, 'N', '002', 'AM05', '01', '987654', 75, 0, '2015-02-10 18:13:19' FROM DUAL UNION ALL
SELECT 'QT01', '20150210', 'I', 29, 'N', '002', 'AM03', '01', '123456', 75, 0, '2015-02-10 17:58:46' FROM DUAL UNION ALL
SELECT 'QT01', '20150210', 'I', 28, 'N', '002', 'AM03', '01', '567890-', 125, 0, '2015-02-10 17:35:36' FROM DUAL UNION ALL
SELECT 'QT01', '20150504', 'I', 37, 'N', '001', 'AM07', '01', '4F26U', 50, 0, '2015-06-08 08:21:33' FROM DUAL UNION ALL
SELECT 'QT06', '20150506', 'I', 36, 'N', '001', 'AB23', '01', '15010003', 250, 0, '2015-06-08 08:20:42' FROM DUAL UNION ALL
SELECT 'QT01', '20150522', 'I', 31, 'N', '001', 'AM02', '01', '5E6021U', 575, 0, '2015-06-08 08:12:26' FROM DUAL UNION ALL
SELECT 'QT06', '20150604', 'I', 32, 'N', '001', 'AM19', '01', '1514507', 250, 0, '2015-06-08 08:16:56' FROM DUAL UNION ALL
SELECT 'QT06', '20150606', 'I', 34, 'N', '001', 'AM20', '01', '150907', 250, 0, '2015-06-08 08:18:57' FROM DUAL UNION ALL
SELECT 'QT01', '20150608', 'I', 38, 'N', '002', 'AM02', '01', '5E6021U', 575, 0, '2015-06-08 08:23:26' FROM DUAL UNION ALL
SELECT 'QT01', '20150707', 'I', 39, 'N', '002', 'AM02', '01', '1111', 250, 0, '2015-07-07 09:53:34' FROM DUAL UNION ALL
SELECT 'QT01', '20160125', 'I', 44, 'N', '002', 'AM02', '01', '5L4027U', 350, 0, '2016-01-26 15:35:06' FROM DUAL UNION ALL
SELECT 'QT01', '20160126', 'I', 43, 'N', '002', 'AM03', '01', '5L09P', 1000, 0, '2016-01-26 15:31:27' FROM DUAL UNION ALL
SELECT 'QT01', '20160126', 'I', 45, 'N', '002', 'AM02', '01', '6A2005U', 1000, 0, '2016-01-26 15:36:57' FROM DUAL UNION ALL
SELECT 'QT01', '20160716', 'I', 42, 'M', '002', 'AM02', '01', 'F4020', 36, 0, '2015-07-16 15:36:26' FROM DUAL UNION ALL
SELECT 'QT01', '20150210', 'O', 03, 'MP', '11212305', 'AM03', '01', 'NQT0120150210001', 0, 5, '2015-02-10 17:39:22' FROM DUAL UNION ALL
SELECT 'QT01', '20150210', 'O', 02, 'NM', '11212305', 'AM03', '01', 'NQT0120150210001', 0, 25, '2015-02-10 17:36:52' FROM DUAL UNION ALL
SELECT 'QT02', '20150210', 'O', 07, 'MP', '11212505', 'AM05', '01', 'NQT0220150210001', 0, 15, '2015-02-10 18:15:50' FROM DUAL UNION ALL
SELECT 'QT02', '20150210', 'O', 06, 'NP', '11212505', 'AM05', '01', 'NQT0220150210001', 0, 25, '2015-02-10 18:15:17' FROM DUAL UNION ALL
SELECT 'QT02', '20150210', 'O', 05, 'NR', '11212505', 'AM05', '01', 'NQT0220150210001', 0, 25, '2015-02-10 18:14:00' FROM DUAL UNION ALL
SELECT 'QT01', '20150210', 'O', 04, 'NM', '11212508', 'AM03', '01', 'NQT0120150210007', 0, 25, '2015-02-10 18:06:00' FROM DUAL
)
SELECT s.rawcod
, s.iodate
, s.io
, s.seq
, s.iotype, t.name AS iotype
, s.vendcd, v.company
, s.grade, g.name AS gradenm
, s.colorcd, c.name AS colornm
, s.lotno
, s.pur_qty
, s.out_qty
, s.cre_date
FROM slips s
LEFT JOIN sycmms01 t ON t.major = 'RT' AND t.minor = s.iotype
LEFT JOIN sycmms01 r ON r.major = 'QT' AND r.minor = s.rawcod
LEFT JOIN sycmms01 g ON g.major = 'GR' AND g.minor = s.grade
LEFT JOIN sycmms01 c ON c.major = 'CL' AND c.minor = s.colorcd
LEFT JOIN sybsms00 v ON v.sitecd = s.vendcd
WHERE s.iodate BETWEEN '20141115' AND '20151231'
ORDER BY rawcod, iodate, cre_date
RAWCOD IODATE IO SEQ IOTYPE IONAME VENDCD COMPANY GRADE GRADENM COLORCD COLORNM LOTNO PUR_QTY OUT_QTY CRE_DATE
QT01 20141114 I 1 N 신재 002 KEP AM03 FU2020 01 NAT 4H72U 1000 0 2014-11-20 12:04:33
QT01 20141119 I 4 N 신재 002 KEP AM04 F20-52 01 NAT 4F3022U 500 0 2014-11-20 12:28:02
QT01 20141119 I 7 N 신재 002 KEP AM05 F20-52 LOF 01 NAT 4J9030U 200 0 2014-11-20 12:30:36
QT01 20141121 I 9 N 신재 002 KEP AM02 F20-03 01 NAT 4K6020U 825 0 2014-11-26 14:21:20
QT01 20141126 I 11 N 신재 002 KEP AM03 FU2020 01 NAT 4G30U 1000 0 2014-11-26 14:22:51
QT01 20141126 I 12 N 신재 002 KEP AM03 FU2020 01 NAT 4111P 1000 0 2014-11-26 14:23:15
QT01 20141126 I 13 N 신재 002 KEP AM02 F20-03 01 NAT 4K6020U 1000 0 2014-11-26 14:42:41
QT01 20141128 I 15 N 신재 002 KEP AM02 F20-03 01 NAT 4J6021U 1000 0 2014-11-28 09:16:36
QT01 20141128 I 16 N 신재 002 KEP AM03 FU2020 01 NAT 4H27U 1000 0 2014-11-28 09:17:06
QT01 20150102 I 17 N 신재 002 KEP AM03 FU2020 01 NAT 4L28U 75 0 2015-01-08 14:30:02
QT01 20150106 I 18 N 신재 002 KEP AM03 FU2020 01 NAT 4L02P 1200 0 2015-01-08 14:31:05
QT01 20150106 I 19 N 신재 002 KEP AM02 F20-03 01 NAT 4L4122U 750 0 2015-01-08 14:31:43
QT01 20150210 I 28 N 신재 002 KEP AM03 FU2020 01 NAT 567890- 125 0 2015-02-10 17:35:36
QT01 20150210 O 2 NM 신재->배합창고 11212305 150TON10호기 AM03 FU2020 01 NAT NQT0120150210001 0 25 2015-02-10 17:36:52
QT01 20150210 O 3 MP 사용대기(배합)->생산 11212305 150TON10호기 AM03 FU2020 01 NAT NQT0120150210001 0 5 2015-02-10 17:39:22
QT01 20150210 I 29 N 신재 002 KEP AM03 FU2020 01 NAT 123456 75 0 2015-02-10 17:58:46
QT01 20150210 O 4 NM 신재->배합창고 11212508 120TON9호기 AM03 FU2020 01 NAT NQT0120150210007 0 25 2015-02-10 18:06:00
QT01 20150504 I 37 N 신재 001 신일상사 AM07 F2U2020 LOF 01 NAT 4F26U 50 0 2015-06-08 08:21:33
QT01 20150522 I 31 N 신재 001 신일상사 AM02 F20-03 01 NAT 5E6021U 575 0 2015-06-08 08:12:26
QT01 20150608 I 38 N 신재 002 KEP AM02 F20-03 01 NAT 5E6021U 575 0 2015-06-08 08:23:26
QT01 20150707 I 39 N 신재 002 KEP AM02 F20-03 01 NAT 1111 250 0 2015-07-07 09:53:34
QT01 20160125 I 44 N 신재 002 KEP AM02 F20-03 01 NAT 5L4027U 350 0 2016-01-26 15:35:06
QT01 20160126 I 43 N 신재 002 KEP AM03 FU2020 01 NAT 5L09P 1000 0 2016-01-26 15:31:27
QT01 20160126 I 45 N 신재 002 KEP AM02 F20-03 01 NAT 6A2005U 1000 0 2016-01-26 15:36:57
QT01 20160716 I 42 M 배합 002 KEP AM02 F20-03 01 NAT F4020 36 0 2015-07-16 15:36:26
QT02 20150106 I 23 N 신재 002 KEP AC06 F20-03 LOF 01 NAT 4I9011U 200 0 2015-01-08 14:34:49
QT02 20150106 I 24 N 신재 002 KEP AM05 F20-52 LOF 01 NAT 4K9022U 75 0 2015-01-08 14:36:02
QT02 20150210 I 30 N 신재 002 KEP AM05 F20-52 LOF 01 NAT 987654 75 0 2015-02-10 18:13:19
QT02 20150210 O 5 NR 신재->대기 11212505 150TON10호기 AM05 F20-52 LOF 01 NAT NQT0220150210001 0 25 2015-02-10 18:14:00
QT02 20150210 O 6 NP 대기->생산 11212505 150TON10호기 AM05 F20-52 LOF 01 NAT NQT0220150210001 0 25 2015-02-10 18:15:17
QT02 20150210 O 7 MP 사용대기(배합->생산) 11212505 150TON10호기 AM05 F20-52 LOF 01 NAT NQT0220150210001 0 15 2015-02-10 18:15:50
QT05 20150106 I 21 N 신재 003 SOLVAY AM12 1015CR 01 NAT 14340B1 175 0 2015-01-08 14:33:18
QT06 20141111 I 5 N 신재 003 SOLVAY AM19 2110R 01 NAT 1429207 475 0 2014-11-20 12:28:50
QT06 20141125 I 10 N 신재 003 SOLVAY AM20 2710HI 01 NAT 1428707 850 0 2014-11-26 14:22:21
QT06 20141128 I 14 N 신재 003 SOLVAY AM19 2110R 01 NAT 1431907 1000 0 2014-11-28 09:15:56
QT06 20150106 I 20 N 신재 003 SOLVAY AM19 2110R 01 NAT 1435607 500 0 2015-01-08 14:32:35
QT06 20150106 I 22 N 신재 003 SOLVAY AM20 2710HI 01 NAT 1428707 200 0 2015-01-08 14:33:55
QT06 20150506 I 36 N 신재 001 신일상사 AB23 1021ST 01 NAT 15010003 250 0 2015-06-08 08:20:42
QT06 20150604 I 32 N 신재 001 신일상사 AM19 2110R 01 NAT 1514507 250 0 2015-06-08 08:16:56
QT06 20150606 I 34 N 신재 001 신일상사 AM20 2710HI 01 NAT 150907 250 0 2015-06-08 08:18:57
아래 같이 원장 형식으로 조회하려 합니다.
일 자 구 분 매입처/설비명 GRADE 색상 LOTNO 입 고 출 고 재 고 저장 일시
2014-11-15 ** 이 월 ** 1,000 1,000 2010-12-31 13:01:00
2014-11-19 신재 KEP F20-52 NAT 4F3022U 500 1,500 2014-11-20 12:28:02
2014-11-19 신재 KEP F20-52 LOF NAT 4J9030U 200 1,700 2014-11-20 12:30:36
2014-11-21 신재 KEP F20-03 NAT 4K6020U 825 2,525 2014-11-26 14:21:20
2014-11-26 신재 KEP FU2020 NAT 4G30U 1,000 3,525 2014-11-26 14:22:51
2014-11-26 신재 KEP FU2020 NAT 4111P 1,000 4,525 2014-11-26 14:23:15
2014-11-26 신재 KEP F20-03 NAT 4K6020U 1,000 5,525 2014-11-26 14:42:41
2014-11-28 신재 KEP F20-03 NAT 4J6021U 1,000 6,525 2014-11-28 09:16:36
2014-11-28 신재 KEP FU2020 NAT 4H27U 1,000 7,525 2014-11-28 09:17:06
** 월 계 ** 7,525 7,525 2014-11-28 09:17:06
** 누 계 ** 7,525 7,525 2014-11-28 09:17:06
2015-01-02 신재 KEP FU2020 NAT 4L28U 75 7,600 2015-01-08 14:30:02
2015-01-06 신재 KEP FU2020 NAT 4L02P 1,200 8,800 2015-01-08 14:31:05
2015-01-06 신재 KEP F20-03 NAT 4L4122U 750 9,550 2015-01-08 14:31:43
** 월 계 ** 2,025 9,550 2015-01-08 14:31:43
** 누 계 ** 9,550 9,550 2015-01-08 14:31:43
2015-02-10 신재 KEP FU2020 NAT 567890- 125 9,675 2015-02-10 14:35:36
2015-02-10 신재->배합창고 150TON 10호기 FU2020 NAT NQT0120150210001 25 9,650 2015-02-10 17:36:52
2015-02-10 사용대기(배합)->생산 150TON 10호기 FU2020 NAT NQT0120150210001 5 9,645 2015-02-10 17:39:22
2015-02-10 신재 KEP FU2020 NAT 123456 75 9,720 2015-02-10 17:58:46
2015-02-10 신재->배합창고 120TON 9호기 FU2020 NAT NQT0120150210007 25 9,695 2015-02-10 18:06:00
** 월 계 ** 200 55 9,695 2015-02-10 18:06:00
** 누 계 ** 9,750 55 9,695 2015-02-10 18:06:00
2015-05-04 신재 신일상사 F2U2020 LOF NAT 4F26U 50 10,320 2015-06-08 20:21:33
2015-05-22 신재 신일상사 F20-03 NAT 5E6021U 575 10,270 2015-06-08 20:12:26
** 월 계 ** 625 10,320 2015-06-08 20:21:33
** 누 계 ** 10,375 55 10,320 2015-06-08 20:21:33
2015-06-08 신재 KEP F20-03 NAT 5E6021U 575 10,895 2015-06-08 20:23:26
** 월 계 ** 575 10,895 2015-06-08 20:23:26
** 누 계 ** 10,950 55 10,895 2015-06-08 20:23:26
2015-07-07 신재 KEP F20-03 NAT 1111 250 11,145 2015-07-07 09:53:34
** 월 계 ** 250 11,145 2015-07-07 09:53:34
** 누 계 ** 11,200 55 11,145 2015-07-07 09:53:34
|