|
||
![]() |
![]() ![]()
CREATE TABLE #TEMP_NUM (
NUM INT , QUANTITY INT ) INSERT INTO #TEMP_NUM VALUES (1, 4) INSERT INTO #TEMP_NUM VALUES (2, 4) INSERT INTO #TEMP_NUM VALUES (3, 4) INSERT INTO #TEMP_NUM VALUES (6, 4) INSERT INTO #TEMP_NUM VALUES (7, 3) INSERT INTO #TEMP_NUM VALUES (8, 4) INSERT INTO #TEMP_NUM VALUES (10, 4) SELECT ROW_NUMBER() OVER (ORDER BY NUM ASC) AS RNUM , NUM , QUANTITY INTO #TEMP_NUM_CHK FROM #TEMP_NUM WITH (NOLOCK) SELECT (SELECT REPLACE(ISNULL(STUFF((SELECT CAST('$-$' AS VARCHAR(MAX)) + J.DISP_NUM FROM ( SELECT CONVERT(VARCHAR(5), MIN(NUM)) + '~' + CONVERT(VARCHAR(5), MAX(NUM)) + '('+CONVERT(VARCHAR(5), MAX(QUANTITY))+')' AS DISP_NUM FROM ( SELECT RNUM , NUM , QUANTITY , CASE WHEN RNUM = NUM AND QUANTITY = (SELECT QUANTITY FROM #TEMP_NUM_CHK WITH (NOLOCK) WHERE RNUM = A.RNUM + 1) THEN 'YES' ELSE 'NO' END AS CHECK_NUM FROM #TEMP_NUM_CHK AS A ) AS T WHERE CHECK_NUM = 'YES' GROUP BY CHECK_NUM UNION ALL SELECT CONVERT(VARCHAR(5), NUM) + '('+CONVERT(VARCHAR(5),QUANTITY)+')' FROM ( SELECT RNUM , NUM , QUANTITY , CASE WHEN RNUM = NUM AND QUANTITY = (SELECT QUANTITY FROM #TEMP_NUM_CHK WITH (NOLOCK) WHERE RNUM = A.RNUM + 1) THEN 'YES' ELSE 'NO' END AS CHECK_NUM FROM #TEMP_NUM_CHK AS A ) AS T WHERE CHECK_NUM = 'NO' ) AS J FOR XML PATH('')), 1, 3, ''), ''), '$-$', ', ') AS DISP_NUM) AS TAG1 º°°Å ¾Æ´Ñ°Í °°¾Æ¼ ²ôÀû´ë´Ùº¸´Ï »ý°¢º¸´Ù ¾î·Æ±º¿ä;;; MSSQL Äõ¸®´Ï±î Çѹø µ¹·Áº¸¼¼¿ä~ |
![]() |
![]() ![]() ![]()
Àúµµ º°°Å ¾Æ´Ï¶ó°í »ý°¢ Çß´Ù°¡ Áú¹®±îÁö ¿Ã¸®°Ô µÆ³×¿©~°¨»çÇÕ´Ï´Ù ÁÁÀº ÇÏ·ç º¸³»¼¼¿ä
|
|
|
![]() |
![]() | ¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û | ¸ñ·Ïº¸±â | ![]() |
ÀÌÀü rowÀÇ °ªÀº LAG() OVER()ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¸é °¡Á®¿Ã ¼ö ÀÖ½À´Ï´Ù. (¹Ý´ë´Â LEADÇÔ¼ö)