mysql>selectcount(*) from (select user_key,SUM(CASEWHEN card_level =5THEN0 ELSE1END) AS a from fx_achievement where pay_date between date_sub('2017-10-10 00:00:00',interval30day) and date_sub('2017-10-10 23:59:59',interval1day) groupby user_key having a=0andsum(sale) >=2500) as t1; +--------------------+ |count(*) | +--------------------+ |7234| +--------------------+ 共返回 1 行记录,花费 43200 ms. mysql>selectcount(*) from (select user_key,SUM(CASEWHEN card_level =5THEN0 ELSE1END) AS a from fx_achievement where pay_date between date_sub('2017-10-10 00:00:00',interval30day) and date_sub('2017-10-10 00:00:00',interval1day) groupby user_key having a=0andsum(sale) >=2500) as t1; +--------------------+ |count(*) | +--------------------+ |6748| +--------------------+ 共返回 1 行记录,花费 42455 ms.