首先为 newbee 问题道歉,我对 MySQL 很陌生。
我有 3 张桌子用于简单的摄影比赛:
注册:
ID
UserName
name
LastName
Email
Mobile
照片库:
ID
ImageName
user_id
Status=1
照片投票:
Photo_ID
Date
Time
Status
我需要在给定的时间片上计算每张照片的票数,如果出现平局,我需要先检查获得最后一票的那张。
我提出的查询是:
SELECT v.Photo_ID AS "Photo ID",
g.ImageName AS "Photo URL",
r.UserName AS "Username",
r.name AS "Name",
r.LastName AS "Surname",
r.Email AS "E-Mail",
r.Mobile AS "Phone",
v.Date AS "Last Vote Date",
v.Time AS "Last Vote Time",
COUNT(Photo_ID) AS "Total Votes"
FROM photovote v
INNER JOIN photogallery g ON v.Photo_ID = g.ID
INNER JOIN registration r ON g.user_id = r.ID
WHERE v.Status =1
AND g.Status =1
AND v.Date >20130728
AND v.Date <20130805
GROUP BY 1
ORDER BY 10 DESC, 8 DESC, 9 DESC
然而 ORDER BY 不能正常工作。任何提示都是高度赞赏的。
谢谢,安德里亚