-1

我有一个 35000 行的表。我正在使用左连接来填充需要 67 秒才能加载的数据集。它会影响 Web 应用程序的性能。请帮助我找到解决方案。

SELECT
        SUM(NVL(t2.AFull,0)) as "AFull",
        SUM(NVL(t1.ADisplaying,0)) as "ADisplay",
        t1.name as "Name",
        t1.cname as "C Name",
        t1.START_TIME as "Start Date",
        t1.END_TIME as "End Date",
        t1.cid as "CID"
FROM
        (
         SELECT
            COUNT(aid) AS ADisplaying,
            cmp.name,
            cmp.cname,
            cd.START_TIME,
            cd.END_TIME,
            cmp.cid
         FROM
            c_delivery cd,
            count cmp
         WHERE 
            cmp.cid = cd.cid AND length(aid)>1
         GROUP BY
            cmp.name,
            cmp.cname,
            cd.START_TIME,
            cd.END_TIME,
            cmp.cid
         ) t1
LEFT JOIN
         (  
          SELECT
             COUNT(aid) as AFull,
             cmp.name,
             cmp.cname,
             cd.START_TIME,
             cd.END_TIME,
             cmp.cid
          FROM
             c_delivery cd,
             count cmp
          WHERE
             cmp.cid = cd.cid 
          GROUP BY
             cmp.name,
             cmp.cname,
             cd.START_TIME,
             cd.END_TIME,
             cmp.cid
          )t2
          on  t1.cid = t2.cid
          group by 
               t1.name,t1.cname,t1.START_TIME,t1.END_TIME,t1.cid);

我在同一张桌子上使用左连接。我想将 count(aid) 列作为一个整体,其次我应该排除相同的 count(aid) 列以获取“-”值。

4

2 回答 2

1

尝试:

select sum(case when length(aid) > 1 then 1 else 0 end) "AFull",
       count(aid) as "ADisplay",
       cmp.name "Name",
       cmp.cname "C Name",
       cd.START_TIME "Start Date",
       cd.END_TIME "End Date",
       cmp.cid "CID"
from c_delivery cd
join count cmp on cmp.cid = cd.cid
GROUP BY cmp.name, cmp.cname, cd.START_TIME, cd.END_TIME, cmp.cid
于 2013-10-30T11:35:10.593 回答
0

试试这个:

SELECT
      SUM ( COUNT ( * ) ) AS "AFull",
      SUM ( COUNT ( CASE
                    WHEN CHECK > 1
                    THEN
                        1
                    ELSE
                        0
                END ) )
          AS "ADisplay",
      NAME AS "Name",
      CNAME AS "C Name",
      START_TIME AS "Start Date",
      END_TIME AS "End Date",
      CID AS "CID"
FROM
      (SELECT
            NAME,
            CNAME,
            START_TIME,
            END_TIME,
            CID,
            LENGTH ( AID ) AS CHECK
       FROM
            C_DELIVERY CD,
            COUNT CMP
       WHERE
            CMP.CID = CD.CID)
GROUP BY
      CMP.NAME,
      CMP.CNAME,
      CD.START_TIME,
      CD.END_TIME,
      CMP.CID
于 2013-10-30T11:21:09.060 回答