select t1.month_id, count(distinct case when t1.offer_type_name='主套餐' then offer_name end) aa, count(distinct case when t1.offer_type_name='促销' then offer_name end) bb, count(distinct case when t1.offer_type_name='可选包' then offer_name end) cc, count(distinct case when t2.offer_type_name='主套餐' then offer_name end) aaa, count(distinct case when t2.offer_type_name='促销' then offer_name end) bbb, count(distinct case when t2.offer_type_name='可选包' then offer_name end) ccc, from zone_crmchk.dwd_sum_zhuliuxxsc t1 left join zone_crmchk.dwd_sum_zhuliuxxsc t2 on t2.month < t1.month group by t1.month, count(distinct case when offer_type_name='主套餐' then offer_name end) aa, count(distinct case when offer_type_name='促销' then offer_name end) bb, count(distinct case when offer_type_name='可选包' then offer_name end) cc
时间: 2024-02-17 20:01:27 浏览: 98
根据您提供的 SQL 查询语句,我发现其中存在一个逗号(,)出现在了 FROM 子句之后,这是一个语法错误。您需要将逗号(,)删除,同时将查询语句修改为如下形式:
```
SELECT
t1.month_id,
COUNT(DISTINCT CASE WHEN t1.offer_type_name='主套餐' THEN offer_name END) aa,
COUNT(DISTINCT CASE WHEN t1.offer_type_name='促销' THEN offer_name END) bb,
COUNT(DISTINCT CASE WHEN t1.offer_type_name='可选包' THEN offer_name END) cc,
COUNT(DISTINCT CASE WHEN t2.offer_type_name='主套餐' THEN offer_name END) aaa,
COUNT(DISTINCT CASE WHEN t2.offer_type_name='促销' THEN offer_name END) bbb,
COUNT(DISTINCT CASE WHEN t2.offer_type_name='可选包' THEN offer_name END) ccc
FROM
zone_crmchk.dwd_sum_zhuliuxxsc t1
LEFT JOIN zone_crmchk.dwd_sum_zhuliuxxsc t2 ON t2.month < t1.month
GROUP BY
t1.month_id,
COUNT(DISTINCT CASE WHEN offer_type_name='主套餐' THEN offer_name END),
COUNT(DISTINCT CASE WHEN offer_type_name='促销' THEN offer_name END),
COUNT(DISTINCT CASE WHEN offer_type_name='可选包' THEN offer_name END);
```
这样修改后,查询语句应该就能正确执行了。
阅读全文