我有一个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(辅助)列作为一个整体,然后我应该排除具有' - '值的相同计数(辅助)列。
答案 0 :(得分: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
答案 1 :(得分: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