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
--大概意思,自己给添完整,或者说明所有相关表结构

解决方案 »

  1.   

    select count(distinct convert(char(7),时间字段,120)) from table1
      

  2.   

    create table test (id char(10),date1 datetime)
    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
    應該是這個意思把
      

  3.   

    select count(*)
    from  table1
    group by left(convert(char(10),[date],120),7)
      

  4.   

    如果是多用户的话:select 用户,count(distinct convert(char(7),时间字段,120))as 次数 from  table1
    group by 用户