위는 본테이블이고 아래는 원하는 결과값입니다.
AAA 라는 컬럼 각각 하나의 로우만 가져오고싶습니다.
결과값은 A, 1, ! 이지만, 'A, 2, @ 가 나와도 관계없습니다. 즉, A 란 데이터의 어느 로우든 상관없다는 뜻입니다.
Comment 6
-
후알유?
2017.01.13 16:11
-
thrill
2017.01.13 16:26
WITH DTAS(SELECT 'A' AAA, '1' BBB ,'!' CCCUNION ALLSELECT 'A' AAA, '2' BBB ,'@' CCCUNION ALLSELECT 'A' AAA, '3' BBB ,'#' CCCUNION ALLSELECT 'B' AAA, '4' BBB ,'$' CCCUNION ALLSELECT 'B' AAA, '5' BBB ,'%' CCCUNION ALLSELECT 'C' AAA, '6' BBB ,'#' CCCUNION ALLSELECT 'C' AAA, '7' BBB ,'@' CCC)SELECT AAA, MIN(BBB), MIN(CCC) FROM DTGROUP BY AAA -
후알유?
2017.01.13 16:32
댓글 감사합니다.
하지만 MIN 이나 MAX 처리시엔
A, 1, @ 이런식으로 나올수있지 않을까요?
-
후알유?
2017.01.13 16:33
A,1,! 이든
A,2,@ 든
A,3,# 이렇게나와야합니다.
-
이리
2017.01.13 16:36
WITH DTAS(SELECT 'A' AAA, '1' BBB ,'!' CCCUNION ALLSELECT 'A' AAA, '2' BBB ,'@' CCCUNION ALLSELECT 'A' AAA, '3' BBB ,'#' CCCUNION ALLSELECT 'B' AAA, '4' BBB ,'$' CCCUNION ALLSELECT 'B' AAA, '5' BBB ,'%' CCCUNION ALLSELECT 'C' AAA, '6' BBB ,'#' CCCUNION ALLSELECT 'C' AAA, '7' BBB ,'@' CCC)SELECT AAA, BBB, CCCFROM(SELECT ROW_NUMBER() OVER(PARTITION BY AAA ORDER BY BBB) AS ROW_NUM, AAA, BBB, CCCFROM DT) AS T1WHERE T1.ROW_NUM = 1 -
후알유?
2017.01.13 16:41
이리님 감사합니다 (__)
귀찮으실수있어 해당 쿼리드립니다.
-----------------------------------------------------
SELECT *
INTO #TEST
FROM (
SELECT 'A' AAA, '1' BBB ,'!' CCC
UNION ALL
SELECT 'A' AAA, '2' BBB ,'@' CCC
UNION ALL
SELECT 'A' AAA, '3' BBB ,'#' CCC
UNION ALL
SELECT 'B' AAA, '4' BBB ,'$' CCC
UNION ALL
SELECT 'B' AAA, '5' BBB ,'%' CCC
UNION ALL
SELECT 'C' AAA, '6' BBB ,'#' CCC
UNION ALL
SELECT 'C' AAA, '7' BBB ,'@' CCC
)A
SELECT * FROM #TEST
SELECT *
FROM (
SELECT 'A' AAA ,'1' BBB, '!' CCC
UNION ALL
SELECT 'B' AAA ,'4' BBB, '$' CCC
UNION ALL
SELECT 'C'AAA, '6' BBB ,'#' CCC
) A
DROP TABLE #TEST