为什么这个查询不起作用?

时间:2014-04-17 11:40:24

标签: mysql

#1305 - 功能n.DATE_FORMAT不存在

选择     n.title,     g.title,     DATE_FORMAT(FROM_UNIXTIME(n.data),'%d')天 来自新闻n 内部联接(      SELECT COUNT(id_news)_COUNT,DATE_FORMAT(FROM_UNIXTIME(data),'%d')_day FROM news GROUP BY _day)as n2

ON n2._day = n.DATE_FORMAT(FROM_UNIXTIME(n.data),'%d')

INNER JOIN group请参阅group_id = n。id_group GROUP BY DATE_FORMAT(FROM_UNIXTIME(n.data),'%d')

1 个答案:

答案 0 :(得分:1)

1.您无法在ON Clause

中使用 ALIAS
SELECT
    n.title,
    g.title,
    DATE_FORMAT(FROM_UNIXTIME(n.data), '%d') day
FROM  news as n 
INNER JOIN(
     SELECT COUNT(id_news) _COUNT ,DATE_FORMAT(FROM_UNIXTIME(data), '%d') _day FROM news GROUP BY _day) as n2  
ON n2._day= n.DATE_FORMAT(FROM_UNIXTIME(n.data), '%d')
INNER JOIN `group` AS g ON g.`group_id`=n.`id_group`
GROUP BY DATE_FORMAT(FROM_UNIXTIME(n.data), '%d')