根据喜欢和不喜欢对评论进行排序

时间:2018-04-29 03:46:46

标签: mysql

请帮助,请更正查询,我需要根据喜欢和不喜欢的方式对评论进行排序(即喜欢和解雇的总和:cnt_total = cnt_like + cnt_dislike,上面显示了更多cnt_total),以及cnt_total是平等的 - 按日期排序。 cnt_total只是一个例子,它不在表格中。

包含列的表注释:id_comment,id_user,id_news,comment,id_parent,date_time,cnt_like,cnt_dislike,is_active。

SELECT u.login, c.* 
FROM comments c
LEFT JOIN users u ON u.id = c.id_user
WHERE id_news = '{$id_news}' AND c.is_active = 1 
ORDER BY id_parent, date_time DESC

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT u.login, c.*, c.cnt_like + c.cnt_dislike AS cnt_total 
FROM comments c
LEFT JOIN users u ON u.id = c.id_user
WHERE id_news = '{$id_news}' AND c.is_active = 1 
ORDER BY cnt_total DESC, date_time DESC