我是SQL新手,一直呆在這段代碼上幾天。獲取計數
select distinct Count(AGVGLST.AGVGLST_PIDM) "Count_AGVGLST_PIDM",
Count((select distinct pidm
from donor
where donor.pidm = agvglst_pidm
and donor.cfae_cat IN ('ALMB','ALMX'))) "Cfae"
from AGVGLST
where AGVGLST.AGVGLST_DESG ='1125'
and AGVGLST.AGVGLST_FISC_CODE ='2010'
and not exists(select 'x'
from agvglst b
where b.agvglst_pidm = agvglst_pidm
and b.agvglst_desg <> '1125'
and b.agvglst_fisc_code = '2010')
我試圖讓計數僅此desgination「1125」,所以我需要引用了兩遍,由於某種原因,我得到零個計數,當我知道還有誰捐贈只是特定desgination捐助者。我相信這是我失蹤的愚蠢。
哪個rdbms好嗎? SQL服務器? – Sebas 2013-03-14 13:06:43
此外,你指望這些傢伙,但誰也沒有給任何其他指定任何東西比1125,所以也許這就是你的計數返回0的原因。它可能會清理一些樣本數據。 – Sebas 2013-03-14 13:08:46
sql server.That是對的,我只想計數那些給1125而不是其他任何東西。我確實有數據,我知道捐助者在給定的財政年度只給了1125。所以我知道0是不正確的。 – user2169875 2013-03-14 13:27:32