日期:2014-05-17  浏览次数:20916 次

请教Oracle中的这个SQL语句怎么写
在ACCESS中

SELECT   T.sTrainNo,   T.sTrainName,   C.cCount,   C.iSum,   U.iCount,   L.sName   AS   LName,   N.sContentName,   S.sSchoolName,   S.sAddress,   T.dTrainDate   FROM   ((((BaseTerm   AS   T   INNER   JOIN   BaseSchool   AS   S   ON   T.iSchoolID   =   S.iID)   INNER   JOIN   BaseLevel   AS   L   ON   T.iTrainLevelID   =   L.iID)   INNER   JOIN   BaseContent   AS   N   ON   T.iTrainContentID   =   N.iID)   LEFT   JOIN   (SELECT   sTrainNo,   COUNT(*)   AS   cCount,   SUM(iNum)   AS   iSum   FROM   BaseClass   GROUP   BY   sTrainNo)   AS   C   ON   C.sTrainNo   =   T.sTrainNo)   LEFT   JOIN   (SELECT   sTermID,   COUNT(*)   AS   iCount   FROM   SignUp   GROUP   BY   sTermID)   AS   U   ON   T.sTrainNo   =   U.sTermID   Where   T.dTrainDate   > =   '2005-07-30 '   AND   T.dTrainDate   <=   '2007-07-30 '
说明:
BaseTerm   与   BaseSchool,   BaseLevel,   BaseContent   进行内连接后会生成一个视图
这个试图在外连接   C视图和D视图
这个语句在ACCESS中执行是没有问题的。
因为Oracle版本9.2中没有Inner,请问如果解决



------解决方案--------------------
SELECT T.sTrainNo, T.sTrainName, C.cCount, C.iSum, U.iCount, L.sName LName,
N.sContentName, S.sSchoolName, S.sAddress, T.dTrainDate
FROM ((((BaseTerm T INNER JOIN BaseSchool S ON T.iSchoolID = S.iID)
INNER JOIN BaseLevel L ON T.iTrainLevelID = L.iID)
INNER JOIN BaseContent N ON T.iTrainContentID = N.iID)
LEFT JOIN (SELECT sTrainNo, COUNT(*) cCount, SUM(iNum) iSum
FROM BaseClass GROUP BY sTrainNo) C ON C.sTrainNo = T.sTrainNo)
LEFT JOIN (SELECT sTermID, COUNT(*) iCount FROM SignUp GROUP BY sTermID)
U ON T.sTrainNo = U.sTermID
Where T.dTrainDate > = '2005-07-30 ' AND T.dTrainDate <= '2007-07-30 '
------解决方案--------------------
改一下吧

Where T.dTrainDate > = to_date( '2005-07-30 ', 'yyyy-mm-dd ') AND T.dTrainDate <= to_date( '2007-07-30 ', 'yyyy-mm-dd ')