求大哥们帮忙啊!~!~求表中某一纪录的纪录和,sql语句,好急啊!
我有两张表,投票表(Vote),教师信息表(TeacherInfo),
其中投票表的字段有:
VotId 投票ID
TeaId 教师ID
VotNumb 投的票数
Vote_Person_Id 投票人ID
VoteDate 投票日期
投一次票 投票表(Vote)增加一条纪录[每次投票票数都是 1],如:
VotId TeaId VotNumb Vote_Person_Id VoteDate
1 1 1 1 2007-9-9
2 1 1 2 2007-9-9
3 2 1 1 2007-9-9
………………
然后在Gridview 中显示出教师所得的票数总和
格式如下:
教师ID 教师姓名 教师所得票数
1 aa 2
2 bb 1
我的SQL 语句如下:
select sum(VotNumb), * from Vote,TeacherInfo where Vote.TeaId = TeacherInfo.TeaId group by Vote.TeaId
报错啊~!
------解决方案--------------------多表查询 需制定字段是出自哪张表
select sum(Vote.VotNumb), * from Vote,TeacherInfo where Vote.TeaId = TeacherInfo.TeaId
------解决方案--------------------try:
select TeacherInfo.*,a.Count from TeacherInfo,(select TeaId ,sum(TeaId) as Count from Vote) a
where TeacherInfo.id = a.TeaId
------解决方案--------------------up
------解决方案--------------------select sum(VotNumb), TI.* from Vote,TeacherInfo TI where Vote.TeaId = TI.TeaId group by Vote.TeaId
你的group by 也有问题 应该是选出的所有字段(除了sum里面的)
------解决方案--------------------select TeacherInfo.*,a.Count from TeacherInfo,(select TeaId ,sum(TeaId) as Count from Vote group by TeaId) a
where TeacherInfo.id = a.TeaId
------解决方案-------------------- select sum(VotNumb),TeacherInfo.* from teacherInfo,vote
where vote.teaId=teacherInfo.TeadId group by teacherInfo.teadid,teacherInfo.教师名
------解决方案--------------------select v.TeaID,t.TeacherName,sum(v.VotNumb) from vote v inner join TeacherInfo t on v.TeaID=t.TeaID
------解决方案-------------------- 't.Name ', 'v.TeaId '