【发布时间】:2019-01-03 16:22:39
【问题描述】:
我使用的是 MySQL Server 5.7,我有这个查询:
select
regDate,
userID,
t.teamID,
login
from
tbl_user u
inner join
tbl_team t on u.userID = t.userID
where
regDate >= DATE_ADD(CURDATE(), INTERVAL -2 MONTH)
AND
(
select sum(transactions) from (
SELECT count(*) as transactions FROM tbl_pp where (fromTeamID = t.teamID or forTeamID = t.teamID) and transactionDate >= u.regDate
union all
SELECT count(*) as transactions FROM tbl_psc where (fromTeamID = t.teamID or toTeamID = t.teamID) and transactionDate >= u.regDate
union all
SELECT count(*) as transactions FROM tbl_mp where (fromTeamID = t.teamID or forTeamID = t.teamID) and transactionDate >= u.regDate
) as all
) > 0
我收到此错误:
错误代码:1054。“where 子句”中的未知列“t.teamID”
我确定这只是一个小问题,但我现在无法解决。并且teamID 列存在于表tbl_team 中。有人给我提示吗?
【问题讨论】:
标签: mysql sql correlated-subquery