如何通过另一个表的列进行排序并从其他表列中获取计数,以便我可以按此顺序排序。
例如:
$sql="SELECT * FROM photos, views WHERE photos.unqid = views.photoid ORDER BY CAST(views.id AS SIGNED)";
我想将照片添加到照片中。所以照片是由观点订购的。
答案 0 :(得分:1)
如下所示
SELECT p.*, v.*, COUNT(v.photoid) as nb_views
FROM photos p, views v
WHERE p.unqid = v.photoid
GROUP BY v.photoid
ORDER BY nb_views