我是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