0
我有這個查詢,我從三個不同的表中計算值,並從每個表中獲取兩列,日期和計數。前12名獲得3條記錄第二名,12名獲得第三名。最後,我從這些表中的計數列做了小計算,從第二列的日期找到匹配..基於日期的計算計算
例如,如果第一個表列的日期與第二個和第三個匹配,我將所有這些價值和它越來越百分比...雖然我已經創造了它的查詢......但它得到了正確的給數據做
我需要知道我怎麼會日期的基礎上進行計算表格這張表..我使用Oracle數據庫
SELECT TRUNC(ans.date),
(a.count1+b.count2+c.count3)*100/count4 AS status
FROM
(SELECT COUNT(pans.actual)count1,
TRUNC(ans.date) AS subdate
FROM pans, ans
WHERE pans.actres ='1'
AND TRUNC(anss.date) > sysdate-100
AND pans.id = anss.id
GROUP BY TRUNC(anss.date)
)a,
(SELECT COUNT(conans.actres)count2,
TRUNC(anss.date) AS subdate
FROM conans, anss
WHERE conans.actres ='1'
AND TRUNC(anss.date) > sysdate-100
AND conans.id = anss.id
GROUP BY TRUNC(anss.date)
)b,
(SELECT COUNT(anss.submitted)count3,
TRUNC(anss.date) AS subdate
FROM anss
WHERE submitted = 1
AND TRUNC(anss.date) > sysdate-100
GROUP BY TRUNC(anss.date)
)c,
(SELECT COUNT(pans.actres) count4
FROM pans, anss
WHERE anss.date > sysdate-100
)d,
anss,
pans
WHERE a.subdate = b.subdate
AND b.subdate = c.subdate
AND a.subdate = c.subdate
AND TRUNC(anss.date) > sysdate-100
GROUP BY TRUNC(anss.date),a.count1,b.count2,c.count3,d.count4
count1
------------------
count | date
3 | 12/12/1928
5 | 12/12/1998
6 | 12/12/1995
count2
------------------
count| date
3 | 12/12/1928
5 | 12/12/1998
6 | 12/12/1995
23 | 12/12/1924
56 | 12/12/1993
68 | 12/12/1992
39 | 12/12/1921
58 | 12/12/1990
63 | 12/12/1999
count3
------------------
count| date
3 | 12/12/1928
5 | 12/12/1998
6 | 12/12/1995
23 | 12/12/1924
56 | 12/12/1993
68 | 12/12/1992
39 | 12/12/1921
58 | 12/12/1990
63 | 12/12/1999
count4
------------------
4500
現在我已經計算
(count1+count2+count3)*100/count4
when count1.date=count2date=count3.date
HTH