我正在使用ROWNUM以下列方式获取999行:
SELECT COUNT(*)
FROM PS_MMC_JOBDSSOA_MV JOB, PS_MMC_PERDSSOA_MV PER
WHERE PER.EMPLID = JOB.EMPLID AND
PER.ASOFDATE = (SELECT MAX(PER1.ASOFDATE) FROM PS_MMC_PERDSSOA_MV PER1
WHERE PER1.EMPLID = PER.EMPLID AND PER1.ASOFDATE <= SYSDATE) AND
JOB.ASOFDATE = (SELECT MAX(JOB1.ASOFDATE) FROM PS_MMC_JOBDSSOA_MV JOB1
WHERE JOB1.EMPLID = JOB.EMPLID AND JOB1.ASOFDATE <=SYSDATE) AND ROWNUM<1000;
我使用左外连接重写了上面的sql查询:
SELECT COUNT(*)
FROM PS_MMC_JOBDSSOA_MV JOB LEFT OUTER JOIN PS_MMC_PERDSSOA_MV PER
ON (PER.EMPLID = JOB.EMPLID)
AND PER.ASOFDATE = ((SELECT MAX(PER1.ASOFDATE) FROM PS_MMC_PERDSSOA_MV PER1 WHERE
PER1.EMPLID = PER.EMPLID AND PER1.ASOFDATE <= SYSDATE)
AND JOB.ASOFDATE = (SELECT MAX(JOB1.ASOFDATE) FROM PS_MMC_JOBDSSOA_MV JOB1 WHERE
JOB1.EMPLID = JOB.EMPLID AND JOB1.ASOFDATE <= SYSDATE)) WHERE ROWNUM <1000;
ROWNUM无法使用外部联接。我的行数超过1000行。
有人能说出我做错了吗。
答案 0 :(得分:0)
我在下面找到了与ROWNUM一起使用的SQL查询
SELECT * from (SELECT JOB.DEPTID, JOB.EMPL_STATUS, JOB.LOCATION, JOB.MMC_LOCATION_DESCR, JOB.CITY, JOB."STATE", PER."NAME" FROM
PS_MMC_JOBDSSOA_MV JOB LEFT OUTER JOIN PS_MMC_PERDSSOA_MV PER ON (PER.EMPLID = JOB.EMPLID)
AND PER.ASOFDATE = (SELECT MAX(PER1.ASOFDATE) FROM PS_MMC_PERDSSOA_MV PER1
WHERE PER1.EMPLID = PER.EMPLID AND PER1.ASOFDATE <= SYSDATE) AND JOB.ASOFDATE =
(SELECT MAX(JOB1.ASOFDATE) FROM PS_MMC_JOBDSSOA_MV JOB1 WHERE JOB1.EMPLID = JOB.EMPLID AND JOB1.ASOFDATE <= SYSDATE))
where ROWNUM <1000