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列)
答案 0 :(得分: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
答案 1 :(得分: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