select 用户,case when c=0 then 1 else c end as 次数
from (
select 用户,sum(case when (包月用户条件) then 0 else 1 end) as c
from ...
group by 用户
) as a
--大概意思,自己给添完整,或者说明所有相关表结构
from (
select 用户,sum(case when (包月用户条件) then 0 else 1 end) as c
from ...
group by 用户
) as a
--大概意思,自己给添完整,或者说明所有相关表结构
insert into test values('012545','2005-6-15')
insert into test values('012545','2005-6-30')
insert into test values('012545','2005-7-30')
insert into test values('012545','2005-8-15')
insert into test values('012545','2005-8-30')
select month(date1) from test
select count(distinct month(date1)) from test
結果3
應該是這個意思把
from table1
group by left(convert(char(10),[date],120),7)
group by 用户