下面是我的代码的副本,我的主要目标是根据其photo_id获取某些图像的等级。下面的代码工作得很好,但问题是,如果有总关系点,那么这两个图像得到相同的排名。我真正想要的是,如果这些图像具有相同的总分,我想按日期对它们进行排名。我怎么能做到这一点?
SELECT uo.*,
( SELECT COUNT(DISTINCT ui.total_points)
FROM photo_list ui
WHERE ui.total_points>= uo.total_points
) AS rank
FROM photo_list uo
WHERE photo_id = :photo_id
以下是我的表格:
id | photo_id | total_points | date
1 432cfc 0 1403076412
2 fsd324 1 1403076413
3 gd43ds 0 1403076411
这是我的愿望结果:
rank | photo_id | total_points | date
1 fsd324 1 1403076413
2 gd43ds 0 1403076411
3 432cfc 0 1403076412
答案 0 :(得分:0)
select * from (
SELECT uo.*,
(SELECT COUNT(DISTINCT ui.total_points)
FROM photo_list ui
WHERE ui.total_points>= uo.total_points
) AS rank
FROM photo_list uo
WHERE photo_id = :photo_id
) as alias
order by total_points,date;
答案 1 :(得分:0)
这将是查询。
SELECT
( SELECT COUNT(DISTINCT ui.total_points)
FROM photo_list ui
WHERE ui.total_points>= uo.total_points
) AS rank,uo.photo_id,uo.total_points,uo.date1
FROM photo_list uo
ORDER BY rank ASC, date1 ASC