我遇到了mysql的问题 - 我不熟悉它,希望提高我的技能:)
有这样的代码:
if($where > 0) $query = mysql_query("SELECT img.*, user.user as owner_name, cat.name as cat_name FROM tentego_img AS img LEFT JOIN tablicacms_users AS user ON user.id = img.owner LEFT JOIN tentego_img_cat AS cat ON cat.id = img.cat WHERE img.`is_waiting` LIKE ".$where.$cat." INNER JOIN tentego_img_vote ON tentego_img.id = tentego_img_vote.object_id GROUP BY tentego_img_vote.object_id ORDER BY SUM ( (CASE WHEN tentego_img_vote.vote = '0' THEN '-1' ELSE '1' END) ) DESC LIMIT ".$page.",".$objPerPage);
我需要按投票数进行排序,按降序排序。 它仍然按照自己的方式对结果进行排序。 在表格中我有行:
ID - vote id for table purpose
object_id- id of object joined with another table to show results.
User ID - user id
Vote - where values are 0 for dislike and 1 for like (so -1 for 0, and +1 for 1)
因此,据我所知,我需要总结每个唯一object_id的所有记录,然后按每个的投票值总和进行排序。 此代码在我的脚本提供程序决定升级之前有效,所以现在我不知道如何修复它:(