下面是修改后的代码:

SELECT toStartOfDay(toDateTime(Ds)) AS datetime_day_Ds,
    PlatformType AS PlatformType,
    CASE
        WHEN PlatformType in (3,4) THEN count(DISTINCT UrlContent2)
        ELSE count(DISTINCT ViewContent2)
    END AS index_mergedviewcount
FROM log_iMonkey_Wechat_overview
WHERE 
    Debug = 1 AND 
    PlatformType not IN (0) AND
    Ds >= toDateTime(#day_wechat_views_time.start#) AND
    Ds <= toDateTime(#day_wechat_views_time.end#) + INTERVAL 1 DAY
GROUP BY datetime_day_Ds, PlatformType
ORDER BY datetime_day_Ds DESC, PlatformType DESC

修改后的代码使用了CASE语句来根据PlatformType的值选择不同的计数字段。当PlatformType为3或4时,index_mergedviewcount取值为count(DISTINCT UrlContent2),否则取值为count(DISTINCT ViewContent2)


原文地址: https://www.cveoy.top/t/topic/i0xl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录