错误 "Unknown column in where clause" - 出了什么问题?
Error "Unknown column in where clause" - What is wrong?
我正在使用 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
我收到这个错误:
Error Code: 1054. Unknown column 't.teamID' in 'where clause'
我确定这只是一个小问题,但我现在无法解决。 teamID
列存在于 table tbl_team
中。有人给我提示吗?
您不能将相关引用嵌套超过一个查询深度。无论如何你最好使用 exists
:
select u.regDate, u.userID, t.teamID, u.login
from tbl_user u inner join
tbl_team t
on u.userID = t.userID
where u.regDate >= DATE_ADD(CURDATE(), INTERVAL -2 MONTH) and
(exists (select 1
from tbl_pp p
where t.teamID in (p.fromTeamID, p.forTeamID) and
p.transactionDate >= u.regDate
) or
exists (select 1
from tbl_psc p
where t.teamID in (p.fromTeamID, p.toTeamID) and
p.transactionDate >= u.regDate
) or
exists (select 1
from tbl_mp p
where t.teamID in (p.fromTeamID, p.forTeamID) and
p.transactionDate >= u.regDate
)
)
我正在使用 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
我收到这个错误:
Error Code: 1054. Unknown column 't.teamID' in 'where clause'
我确定这只是一个小问题,但我现在无法解决。 teamID
列存在于 table tbl_team
中。有人给我提示吗?
您不能将相关引用嵌套超过一个查询深度。无论如何你最好使用 exists
:
select u.regDate, u.userID, t.teamID, u.login
from tbl_user u inner join
tbl_team t
on u.userID = t.userID
where u.regDate >= DATE_ADD(CURDATE(), INTERVAL -2 MONTH) and
(exists (select 1
from tbl_pp p
where t.teamID in (p.fromTeamID, p.forTeamID) and
p.transactionDate >= u.regDate
) or
exists (select 1
from tbl_psc p
where t.teamID in (p.fromTeamID, p.toTeamID) and
p.transactionDate >= u.regDate
) or
exists (select 1
from tbl_mp p
where t.teamID in (p.fromTeamID, p.forTeamID) and
p.transactionDate >= u.regDate
)
)