WITH x AS (SELECT #{personId} as userID, #{startDate} as startDate, #{endDate} as endDate from dual) SELECT (SELECT COUNT (*) thesisCount FROM KY_ACHIEVETHESIS A JOIN KY_ACHIEVEMENT B ON A.THESISID = B.ACHIEVECONTENTID JOIN KY_ACHIEVEPERSON C ON C.ACHIEVEITEMID = B.ACHIEVEITEMID, x WHERE B.ACHIEVETYPE = '论文' AND C.PERSONID = x.userID AND A.STATUS = 0 AND (A.publishDate >= x.startDate OR x.startDate IS NULL) AND (A.publishDate <= x.endDate OR x.endDate IS NULL)) LWFROM DUAL
3 回答
已采纳
HansonQ
TA贡献223条经验 获得超56个赞
where 是在两个表join完成后,再附上where条件。
而 and 则是在表连接前过滤A表或B表里面哪些记录符合连接条件,同时会兼顾是left join还是right join。即
假如是左连接的话,如果左边表的某条记录不符合连接条件,那么它不进行连接,但是仍然留在结果集中(此时右边部分的连接结果为NULL)。
建议尽量用where来过滤条件,以避免复杂的逻辑考虑。(除非在某些情况下(后接其他sql语句),用and会报错,才用and,但要考虑是否影响正确结果。)
_朝歌_
TA贡献10条经验 获得超3个赞
在toad to oracle 中执行会报ORA-04044: procedure, function, package, or type is not allowed here。
添加回答
举报
0/150
提交
取消