这是我的代码
select
name, sum(Value) as [Total Donated]
from
CHARITY c
join
DONATION d on c.CharityID = d.CharityID
join
ITEM_DONATION id on d.DonationID = id.DonationID
group by
name, DonationDate
having
DonationDate like '%13%'
order by
name;
和输出
name Total Donated
-------------------- -------------
Boy Scouts 250.00
Boy Scouts 5.00
Focus Hope 5.00
Focus Hope 10.00
Fresh Start Charity 12.00
Helping Hands 2.99
Helping Hands 12.50
Helping Hands 110.50
St. John Hospital 112.00
我以为我已将它设置在童子军应该是一个项目加入到一起并且同样具有焦点希望等等......但是我有点偏离任何人都可以帮助并让我知道我在做什么这里错了吗?
答案 0 :(得分:3)
您需要从DonationDate
子句中删除GROUP BY
并将条件从HAVING
移至WHERE
子句:
select
name
, sum(Value) as [Total Donated]
from CHARITY c
join DONATION d
on c.CharityID = d.CharityID
join ITEM_DONATION id
on d.DonationID = id.DonationID
where
DonationDate like '%13%'
group by name
order by name;