SELECT datetime_day_Dsindex_mergedviewcountFROM SELECT toStartOfDaytoDateTimeDs AS datetime_day_Ds PlatformType AS PlatformType maxMergedUrlCount AS index_mergedviewcount FROM log_iMonkey_We
代码中存在几个问题:
-
SELECT 子查询的语法错误:在子查询中,不能将列名与别名放在同一行,需要将别名放在列名之后。
-
SELECT 子查询的别名冲突:在子查询中,两个子查询都使用了相同的别名 index_mergedviewcount,需要将其中一个别名修改为不同的名称。
-
JOIN 子查询的语法错误:在 JOIN 子查询中,ON 关键字后的条件应该使用等号 (=) 进行连接,而不是使用赋值号 ( = )。
-
JOIN 子查询的别名冲突:在 JOIN 子查询中,两个子查询都使用了相同的别名 datetime_day_Ds,需要将其中一个别名修改为不同的名称。
下面是修改后的代码:
SELECT A.datetime_day_Ds, A.index_mergedviewcount
FROM
(
SELECT toStartOfDay(toDateTime(Ds)) AS datetime_day_Ds,
PlatformType AS PlatformType,
max(MergedUrlCount) AS index_mergedviewcount
FROM log_iMonkey_Wechat_overview
WHERE Debug = 0 AND PlatformType IN (3,4) AND
Ds >= toDateTime(#day_wechat_views_time.start#)
AND Ds <= toDateTime(#day_wechat_views_time.end#)
GROUP BY datetime_day_Ds, PlatformType
ORDER BY datetime_day_Ds DESC, PlatformType DESC
LIMIT 5000
) as A
LEFT JOIN
(
SELECT toStartOfDay(toDateTime(Ds)) AS datetime_day_Ds,
PlatformType AS PlatformType,
max(MergedViewCount) AS index_mergedviewcount
FROM log_iMonkey_Wechat_overview
WHERE Debug = 0 AND PlatformType not IN (0,3,4) AND
Ds >= toDateTime(#day_wechat_views_time.start#)
AND Ds <= toDateTime(#day_wechat_views_time.end#)
GROUP BY datetime_day_Ds, PlatformType
ORDER BY datetime_day_Ds DESC, PlatformType DESC
LIMIT 5000
) as C ON A.datetime_day_Ds = C.datetime_day_Ds
``
原文地址: https://www.cveoy.top/t/topic/hOvc 著作权归作者所有。请勿转载和采集!