如何知道每个月的最大天数?
比如说:
有一系列的日期数据
日期    |
2007-1-7|
2007-1-27|
2007-2-3|
2008-2-9|
.......
如何统计出:
|年月|该月最大天数|
.....|............|

解决方案 »

  1.   

    create table test(日期 datetime)
    insert test select '2007-6-1'
    union all select '2007-6-2'
    union all select '2007-6-3'
    union all select '2007-2-1'
    union all select '2007-2-2'
    union all select '2007-2-3'select 日期,天数=datediff(day,日期+'-01',dateadd(month,1,日期+'-01')) from
    (
    select 日期=convert(char(7),日期,120)
    from test
    group by convert(char(7),日期,120)
    )a
    drop table test
    日期      天数          
    ------- ----------- 
    2007-02 28
    2007-06 30