我有一个 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) 列以获取“-”值。