MYSQL select 上的列别名在使用 Count 时不起作用
MYSQL column alias on select not working when using Count
我必须在两个名为 "plays" 的连接表上使用相似的列,我想区分它们,但我得到 "Unknown column 'p.plays' in 'field list'"。我做错了什么?
SELECT *,
p.plays AS pl,
m.plays AS mp,
COUNT(p.sid) frequency,
FROM music m
JOIN plays p
ON p.sid = m.sid
INNER JOIN users u
ON u.uid = m.uid
INNER JOIN downloads d
ON d.sid = m.sid
WHERE p.time > NOW() - INTERVAL 3 DAY
AND p.sid != ''
AND m.perms != 'c'
GROUP BY m.sid
ORDER BY frequency DESC
LIMIT 50
图片。
TABLE:音乐
TABLE:播放
谢谢。
根据您在编辑中提供的 table 架构。你在 plays
table 中没有 Plays
列,这就是你收到此错误的原因尝试删除此 p.Plays
SELECT *,
m.plays AS mp,
COUNT(p.sid) frequency,
FROM music m
JOIN plays p
ON p.sid = m.sid
INNER JOIN users u
ON u.uid = m.uid
INNER JOIN downloads d
ON d.sid = m.sid
WHERE p.time > NOW() - INTERVAL 3 DAY
AND p.sid != ''
AND m.perms != 'c'
GROUP BY m.sid
ORDER BY frequency DESC
LIMIT 50
我必须在两个名为 "plays" 的连接表上使用相似的列,我想区分它们,但我得到 "Unknown column 'p.plays' in 'field list'"。我做错了什么?
SELECT *,
p.plays AS pl,
m.plays AS mp,
COUNT(p.sid) frequency,
FROM music m
JOIN plays p
ON p.sid = m.sid
INNER JOIN users u
ON u.uid = m.uid
INNER JOIN downloads d
ON d.sid = m.sid
WHERE p.time > NOW() - INTERVAL 3 DAY
AND p.sid != ''
AND m.perms != 'c'
GROUP BY m.sid
ORDER BY frequency DESC
LIMIT 50
图片。
TABLE:音乐
TABLE:播放
谢谢。
根据您在编辑中提供的 table 架构。你在 plays
table 中没有 Plays
列,这就是你收到此错误的原因尝试删除此 p.Plays
SELECT *,
m.plays AS mp,
COUNT(p.sid) frequency,
FROM music m
JOIN plays p
ON p.sid = m.sid
INNER JOIN users u
ON u.uid = m.uid
INNER JOIN downloads d
ON d.sid = m.sid
WHERE p.time > NOW() - INTERVAL 3 DAY
AND p.sid != ''
AND m.perms != 'c'
GROUP BY m.sid
ORDER BY frequency DESC
LIMIT 50