我在查询中遇到此错误,您知道如何将 sdate
放入 2 层子查询中吗?
select
at.startDate as sdate, at.dau as DAU,
(
select count(distinct d.uid) from
(select ses.uid from dsession as ses where ses.startDate = sdate group by ses.uid
union all
select res.uid from rsession as res where res.startDate = sdate group by res.uid) as te
) as MAU, (SELECT DAU/MAU) as AVG
from
attendance as at
如果我单独查询子查询,它会起作用,但是当我将其合并到主查询时,sdate
变得未知。有什么想法吗?
我尝试将 where
上的 sdate
替换为 at.startDate
,但仍然得到未知的 at.startDate
列.
最佳答案
我没有在主 select 子句中进行选择,而是创建了一个子查询来连接,以便可以检查 startDate
SELECT at.startDate AS sdate, at.dau AS DAU, (DAU/MAU.cnt) as AVG
FROM attendance AS at
JOIN (SELECT startdate, count(distinct uid) as cnt
FROM (SELECT uid, startdate FROM dsession
UNION ALL
SELECT uid, startdate FROM rsession) as ua
GROUP BY startdate
) as MAU ON MAU.startdate = at.startdate
希望我在重组查询时没有搞砸任何事情:)
关于mysql - 错误代码 : 1054. 'sdate' 中的未知列 'where clause',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54927792/