第一个选择填充 countOfActivePlans:
SELECT COUNT(DISTINCT a.txtprogram) AS countOfActivePlans, c.txtLevel1
FROM tblOfferings a, tblClaims b, tblRetailers c
WHERE a.ysnActive=1
AND c.intRetailer=b.intRetailer
AND c.intRetailer=a.intRetailer
GROUP BY c.txtLevel1
ORDER BY c.txtLevel1
第二个选择填充plansWithActivity:
SELECT COUNT(DISTINCT a.txtProgram) AS plansWithActivity, c.txtLevel1
FROM tblClaims a, tblOfferings b, tblRetailers
WHERE a.intOffering=b.intOffering
AND c.intRetailer=a.intRetailer
AND c.intRetailer=b.intRetailer
GROUP BY c.txtlevel1
ORDER BY c.txtLevel1
第三个填充 Approved、Denied 和 sumOfcurPaid:
SELECT COUNT(a.dblTransaction) AS invoicesSubmitted, SUM(curPaid) AS sumOfcurPaid, b.txtLevel1,
CASE WHEN a.intTransCode=0 THEN 'Denied'
WHEN a.intTransCode=1 THEN 'Approved'
ELSE 'Reissued'
END AS txtLabel
FROM tblClaims a, tblRetailers b, tbLTransCode c
WHERE a.intRetailer=b.intRetailer
AND a.intTransCode=c.intTransCode
GROUP BY b.txtLevel1,
CASE WHEN a.intTransCode=0 THEN 'Denied'
WHEN a.intTransCode=1 THEN 'Approved'
ELSE 'Reissued'
END
ORDER BY b.txtLevel1 asc
下表如下。
我怎样才能使这个INSERT
填充表格?
Area countOfActivePlans plansWithActivity approved denied sumOfCurPaid
-----------------------------------------------------------------------------
CE 237 230 89898 11438 1238152.858
NE 189 178 54159 5667 1665176.757
SE 177 165 58675 5873 1406241.758
SW 118 111 32450 6934 1329101.503
WE 152 145 40266 3473 529956.6875