所以情况是这样的,我正在使用以下查询从数据库内部获取详细信息加入表2的顺序由desc但我想下摆也是rand()但不知道如何,我有也尝试了子查询,但没有工作,或者我做错了方法:
SELECT *,count(rating.photo_id) cphoto_id FROM rating INNER JOIN photos ON photos.id = rating.photo_id WHERE display = 1 GROUP BY rating.photo_id ORDER BY cphoto_id DESC LIMIT 0,10
帮助将不胜感激。
答案 0 :(得分:0)
select * from (SELECT *,count(rating.photo_id) cphoto_id FROM rating INNER JOIN photos ON photos.id = rating.photo_id WHERE display = 1 GROUP BY rating.photo_id ORDER BY cphoto_id DESC LIMIT 0,10) as alais order by rand();
答案 1 :(得分:0)
试试这个。它可能有用。
编辑:
SELECT * FROM
(SELECT photos.*,rating.*,count(rating.photo_id) cphoto_id
FROM rating INNER JOIN photos ON photos.id = rating.photo_id
WHERE display = 1 GROUP BY rating.photo_id
ORDER BY rand() DESC LIMIT 10)as alias
ORDER BY cphoto_id;