帮我为每一方显示一个名称DATABASE(SQL 2008) [英] help me display one name for each party DATABASE(SQL 2008)
本文介绍了帮我为每一方显示一个名称DATABASE(SQL 2008)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Select Partyy.Party_name,(Total_counts)as votes_for_each_party
From votes,Candidate,Partyy
Where Partyy.Party_id=Candidate.Party_id
And Candidate.Candidate_id=votes.Candidate_id
AND Party_name in(Select distinct Party_name from Candidate )
Group By Partyy.Party_name,votes.Total_counts
Order By Total_counts desc
您能帮我为每一方显示一个名字并在该名字内组合所有结果吗?这是我使用的代码,但并不能为我提供正确的结果.
Can you please help me display one name for each party and combine all their results within that one name.This is the code i used but it is not givivng me the correct results.
推荐答案
SELECT p.Party_name, SUM(v.Total_counts) as Votes_for_each_Party
FROM Partyy as p
JOIN Candidate as c on c.party_id = p.party_Id
JOIN Votes as v on v.candidate_id = c.candidate_id
Group by p.Party_name
Order by Votes_for_each_Party desc
您似乎在正确的轨道上.你的桌子为什么叫派对?结果如何不正确?我怀疑您需要添加的单词"sum"与sum(total_counts)一样,将它们全部加在一起.
It looks like you''re on the right track. Why is your table called partyy ? How is the result not correct ? I suspect what you need to add is the word ''sum'' as in sum(total_counts), to add them all together.
从GROUP BY
条款中删除votes.Total_counts
.
这篇关于帮我为每一方显示一个名称DATABASE(SQL 2008)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文