1
SELECT ROW_NUMBER() 
         OVER( 
           ORDER BY QUESID DESC)                     AS RowNum, 
       QUESID, 
       QUESCATEGORY, 
       QUESTION, 
       ID                                            OptionID, 
       OPTION_NAMES, 
       CONVERT(VARCHAR(9), ISNULL(RA.REVIEWERID, ''))ReviewerID, 
       CONVERT(VARCHAR(9), ISNULL(ANSWER, ''))       Answer 
FROM   EMP_TB_APP_QUESTIONMASTER QM 
       INNER JOIN EMP_TB_EOB_QUESTIONBANK_OBJECTIVEOPTIONS QO 
               ON QM.QUESID = QO.QUESTIONID 
       INNER JOIN EMP_TB_TRAN_PROBATION_REVIEW_FROM_ANSWERS RA 
               ON QO.ID = RA.QUESTIONID 
       INNER JOIN EMP_TB_TRAN_PROBATION_REVIEW_REVIEWER R 
               ON R.REVIEWERID = RA.REVIEWERID 

我需要删除所有重复的行(无需比较 RowNum 列)

4

2 回答 2

0

用于distinct删除重复行

SELECT distinct ROW_NUMBER() 
         OVER( 
           ORDER BY QUESID DESC)                     AS RowNum, 
       QUESID, 
       QUESCATEGORY, 
       QUESTION, 
       ID                                            OptionID, 
       OPTION_NAMES, 
       CONVERT(VARCHAR(9), ISNULL(RA.REVIEWERID, ''))ReviewerID, 
       CONVERT(VARCHAR(9), ISNULL(ANSWER, ''))       Answer 
FROM   EMP_TB_APP_QUESTIONMASTER QM 
       INNER JOIN EMP_TB_EOB_QUESTIONBANK_OBJECTIVEOPTIONS QO 
               ON QM.QUESID = QO.QUESTIONID 
       INNER JOIN EMP_TB_TRAN_PROBATION_REVIEW_FROM_ANSWERS RA 
               ON QO.ID = RA.QUESTIONID 
       INNER JOIN EMP_TB_TRAN_PROBATION_REVIEW_REVIEWER R 
               ON R.REVIEWERID = RA.REVIEWERID 
于 2013-10-09T06:28:28.880 回答
0

ROW_NUMBER在添加到查询之前尝试使用 distinct 。

像这样的东西:

SELECT *, 
       ROW_NUMBER() 
         OVER( 
           ORDER BY QUESID DESC) AS RowNum 
FROM   (SELECT DISTINCT QUESID, 
                        QUESCATEGORY, 
                        QUESTION, 
                        ID                                            OptionID, 
                        OPTION_NAMES, 
                        CONVERT(VARCHAR(9), ISNULL(RA.REVIEWERID, ''))ReviewerID 
                        , 
                        CONVERT(VARCHAR(9), ISNULL( 
                        ANSWER, ''))       Answer 
        FROM   EMP_TB_APP_QUESTIONMASTER QM 
               INNER JOIN EMP_TB_EOB_QUESTIONBANK_OBJECTIVEOPTIONS QO 
                       ON QM.QUESID = QO.QUESTIONID 
               INNER JOIN EMP_TB_TRAN_PROBATION_REVIEW_FROM_ANSWERS RA 
                       ON QO.ID = RA.QUESTIONID 
               INNER JOIN EMP_TB_TRAN_PROBATION_REVIEW_REVIEWER R 
                       ON R.REVIEWERID = RA.REVIEWERID)T 
于 2013-10-09T06:28:38.413 回答