2

我有两个疑问,

SELECT col1,col2,col3
  from scnd1
 where col2<>'' 
 group by col1,col2,col3 
 order by col1

SELECT ROWNUMBER() OVER (PARTITION BY COL1) AS RN FROM SCND1)AS A
 WHERE RN > 1

对于同一张表,我需要单个查询来组合这两个,即。第一个我想对表进行排序以及删除NULL然后通过第二个查询删除重复的行。

4

1 回答 1

0

按照以下方式尝试子查询:

SELECT 
    main.col1, 
    main.col2,
    main.col3 
FROM scnd1 main
JOIN (SELECT 
         col1,
         col2,
         col3, 
         ROW_NUMBER() OVER (PARTITION BY(col1) ORDER BY col1) AS RN
      FROM SCND1
      WHERE col2<>''
) sub
ON sub.Col1 = main.Col1 AND sub.Col2 = main.col2 AND sub.Col3 = main.col3
WHERE RN > 1
GROUP BY main.col1,main.col2,main.col3 
ORDER BY main.col1
于 2012-09-12T09:17:29.427 回答