日期:2014-05-18  浏览次数:20411 次

紧急---求一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,a
where c.uid=a.uid
and a.city_id =1 and a.group_id = 1

select 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')