把select变量放在最近的查询层中,我在查询中失去了选择权。
从此行获取此错误unknown column h.date
我知道原因,因为我把gb.startTime = h.date
放在左连接选择中。我认为这是安排上的问题。
有人知道吗?
这是我的问题:
set @maxBat = 10000;
set @minBat = 0;
select
h.date,
(select
count(*)
from(
select
distinct d.id,
d.reg,
ifnull(bc.battleCount, 0) AS battles
from (
select
ds.id as id,
ds.reg as reg
...
) as d
left join
(
select
count(gb.id) as battleCount,
gb.playerID
from g_battles as gb
where
gb.startTime = h.date
group by gb.playerID
) as bc on bc.playerID = d.id
having battles between @minBat and @maxBat
) as e
where e.reg = h.date
) as regbattle
from
sessiontable as h
where
...
最佳答案
您可以只在一个级别的back子查询中使用外部数据查询,而不是更多,例如,
没关系的
select id,(select count(index_)
from (select index_ from log_sops) as t where t.index_ = h.version)
from data_sops as h where id = 4
但这是错的
select id,(select count(index_)
from (select index_ from log_sops where id = h.version)
as t)
from data_sops as h where id = 4
关于mysql - 如何将where子句变量放在选择查询的第一层,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55619043/