当前位置: 代码迷 >> ASP.NET >> 紧急求一SQL语句!该怎么处理
  详细解决方案

紧急求一SQL语句!该怎么处理

热度:6852   发布时间:2013-02-25 00:00:00.0
紧急---求一SQL语句!!!!
一个投票活动

假设有A B C 三表

【A--用户表】

UID (ID)
GROUP_ID (组别)
CITY_ID (城市)



【B-照片表】

PID (照片ID)
UID (和A表UID关联)



【C-投票表】

UID (和A表UID关联)
PhotoID (和B表PID关联)


投票流程:
当用户投票成功后,往C表写入该用户的UID和所投照片的PID


求助:
需要得出 CITY_ID (城市)=1 和 GROUP_ID (组别)=1 所投的总票数

------解决方案--------------------------------------------------------
SQL code
SELECT COUNT(*) FROM A WHERE A.GROUP_ID = 1 AND A.CITY_ID = 1 AND A.UID IN (SELECT UID FROM C)
------解决方案--------------------------------------------------------
SQL code
select count(*) from c,awhere c.uid=a.uidand a.city_id =1 and a.group_id = 1select count(*) from c where uid in (select uid from a where city_id =1 and group_id = 1)
------解决方案--------------------------------------------------------
select count(*) from c where uid in (select uid from a where group_id='1' and city_id='1')
  相关解决方案