我需要通过 (LIKES (puntuacion=1) - DISLIKE (puntuacion=0) 的结果来排序此查询的结果。
这是我按喜欢的总和(puntuacion = 1)排序的旧查询。
"SELECT entradas.* , SUM(puntuacion) AS total_likes
FROM entradas
LEFT JOIN valoraciones ON valoraciones.entradas_id = entradas.id
and valoraciones.puntuacion=1
WHERE fecha>=:fecha1 AND aceptada=1
GROUP BY entradas.id
ORDER BY `total_likes` DESC
limit 5";
试过这个,但 total_likes / total_dislikes 是时间变量,不能对它们进行操作。
SELECT entradas.* , SUM(puntuacion=1) AS total_likes, SUM(puntuacion=0) AS total_dislikes, total_likes-total_dislikes AS TOTAL
FROM entradas
LEFT JOIN valoraciones ON valoraciones.entradas_id = entradas.id
WHERE aceptada=1
GROUP BY entradas.id
ORDER BY `total_likes` DESC
limit 5