我有以下 sql 查询
SELECT
vmm_user.username,
vmm_songs.*,
vmm_albums.desc,
vmm_albums.release,
vmm_albums.name,
AVG(vmm_songrating.rating) AS ratingavg,
COUNT(vmm_songrating.id) AS ratingcount
FROM
vmm_songs
LEFT JOIN
vmm_user
ON
vmm_songs.userid=vmm_user.id
LEFT JOIN
vmm_albums
ON
vmm_songs.albumid=vmm_albums.id
LEFT JOIN
vmm_songrating
ON
vmm_songs.id=vmm_songrating.songid
GROUP BY
vmm_songs.id
HAVING
COUNT(vmm_songrating.id) >= 2
ORDER BY
AVG(vmm_songrating.rating) DESC
LIMIT
10
这很好用,但现在我必须知道用户是否已经为一首歌投票,这就是我的问题
评级表看起来像这样
id|songid|用户名|评分
我试过这样的东西
SELECT
...
COUNT(vmm_songrating.id) as hasvoted
...
OUTER JOIN
vmm_songrating
ON
vmm_songrating.userid = $id
...
$id 是用户会话 ID
但它不起作用:/