我尝试引用子查询中的列,这是MySql中的一个列本身,但是我收到一条错误,指出引用的列不存在。它可能与MySql执行子查询的方式有关......
SELECT
language AS 'SMS type',
year(ctime) AS 'Year',
monthname(ctime) AS 'Month',
(SELECT count(1)
FROM sms_sent AS t2
LEFT JOIN history ON history_id = history.id
WHERE language = `SMS type`
AND ctime <= date_sub(makedate(year(t1.ctime), month(t1.ctime)*30), interval 1 month)
GROUP BY language, monthname(ctime)) AS 'Previous month',
FROM sms_sent as t1
LEFT JOIN history ON history_id = history.id
GROUP BY language, monthname(ctime)
有趣的是,如果我从子查询中引用外部查询Year的列为Year
,那么它的工作原理...就是在外部查询中我想使用monthname()函数而在子查询中的month()函数...