2014-08-28 77 views
-2

使用一組由A組選擇stament通過使用組組select語句

SELECT 
    k.Ivalue, k.JOBDESCRIPTION , 
    count(k.Ivalue) as TOTAL 
FROM 
    (SELECT 
     a."ID" as Ivalue, b."JOBDESCRIPTION", rq."CURRENTSTATUS" 
    FROM 
     tblG2o_Requests a 
    INNER JOIN 
     tblG2o_JOBS b ON a."JOBPOSTID" = b."ID" 
    INNER JOIN 
     (SELECT 
      r.REQUESTID, ir."CURRENTSTATUS" 
     FROM 
      TBLG2O_RESULTSPOOL r 
     INNER JOIN 
      tblG2o_Requests ir ON r.RequestID = ir."ID" 
     WHERE 
      r.ShortListed = '1') rq ON rq.REQUESTID = a."ID" 
    WHERE 
     "ACTIVE" = '1' 
     AND "DATECOMPLETED" IS NULL 
    ORDER BY 
     "REQUESTDATE" DESC) k 
GROUP BY 
    k.JOBDESCRIPTION 
+0

您使用了哪個數據庫?你有什麼問題? – 2014-08-28 11:13:54

+0

現在用的Navicat訪問Oracle 12.收到此錯誤[ERR] ORA-00932:不一致的數據類型:預期 - 得到CLOB – Prince 2014-08-28 13:40:36

回答

1

問題是什麼?你似乎BY子句缺少組,你不需要圍繞字段名雙引號,除非你在裏面有空格,即使如此,如果TSQL例如,你會優先使用[]。

我不得不在子查詢中刪除ORDER BY,這是不允許的,除非其他條件需要(像TOP N在TSQL)

SELECT 
     k.Ivalue 
    , k.JOBDESCRIPTION 
    , COUNT(k.Ivalue) AS TOTAL 
FROM (
      SELECT 
        a.ID AS Ivalue 
       , b.JOBDESCRIPTION 
       , rq.CURRENTSTATUS 
      FROM tblG2o_Requests a 

        INNER JOIN tblG2o_JOBS b 
           ON a.JOBPOSTID = b.ID 
        INNER JOIN (
           SELECT 
            r.REQUESTID 
            , ir.CURRENTSTATUS 
           FROM TBLG2O_RESULTSPOOL r 
            INNER JOIN tblG2o_Requests ir 
               ON r.RequestID = ir.ID 
           WHERE r.ShortListed = '1' 
         ) rqenter 
           ON rq.REQUESTID = a.ID 
      WHERE ACTIVE = '1' 
        AND DATECOMPLETED IS NULL 
    ) k 
GROUP BY 
     k.Ivalue 
    , k.JOBDESCRIPTION 
+0

升收到以下錯誤= [ERR] ORA-00932:不一致的數據類型:預期 - 有CLOB – Prince 2014-08-28 13:17:37

+0

莫非' ACTIVE'是整數?將'1'改爲1可否將'r.ShortListed'設爲整數?更改「1」,1如果沒有幫助,請閱讀錯誤的細節仔細http://ora-00932.ora-code.com/ ::我什麼都不知道這些表中的數據類型,所以我不能提供任何洞察力;請記住您提供的大部分查詢。 – 2014-08-28 14:02:05

+0

你可能會嘗試的一件事,註釋掉引用'JOBDESCRIPTION'的每一行就是CLOB?使用'describe'來了解數據類型的字段。 – 2014-08-28 14:04:31

0

終於摸索

選擇 k.Ivalue ,l.JOBDESCRIPTION ,k.TOTAL, k.CURRENTSTATUS FROM(SELECT a.ID AS Ivalue ,b.ID如JobPostID ,RQ。 「CURRENTSTATUS」 ,COUNT(a.ID)AS TOTAL FROM tblG2o_Requests一個

   INNER JOIN tblG2o_JOBS b 
          ON a."JOBPOSTID" = b.ID 
       INNER JOIN (
          SELECT 
           r."REQUESTID" 
           , ir."CURRENTSTATUS" 
          FROM TBLG2O_RESULTSPOOL r 
           INNER JOIN tblG2o_Requests ir 
              ON r."REQUESTID" = ir.ID 
          WHERE r."SHORTLISTED" = 1 
        ) rq 

          ON rq."REQUESTID" = a.ID 
     WHERE ACTIVE = '1' 
       AND DATECOMPLETED IS NULL 

GROUP BY a.ID,b.ID ,RQ。 「CURRENTSTATUS」)K 內加入tblG2o_JOBS l on k.JobPostID = l.ID

enter code here