使用Count时,选择MYSQL列别名不起作用

时间:2015-04-04 05:57:21

标签: mysql sql database inner-join alias

我必须在两个名为" play"的连接表上使用相似的列,我想区分它们,但我得到了#34;未知栏' p.plays'在'字段列表'"。我做错了什么?

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

图像。

表:音乐

Music Table

表:播放

plays table

感谢。

1 个答案:

答案 0 :(得分:0)

根据您在编辑中提供的表架构。您在Plays表格中没有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