select distinct year(addtime) ..

解决方案 »

  1.   

    select 
    2008
    union all
    2009
    union all
    2010
      

  2.   

    SELECT DISTINCT YEAR(addtime) FROM tb;
      

  3.   

    addtime 
    ------- 
    2008
    2009
    2010(所影响的行数为 3 行)
      

  4.   

    ----------------------------------------------------------------
    -- Author :fredrickhu(小F 向高手学习)
    -- Date   :2009-07-01 10:07:54
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    create table [tb]([addtime] datetime,[C2] varchar(8))
    insert [tb]
    select '2009-06-01','11:11:11' union all
    select '2009-06-01','11:11:11' union all
    select '2008-06-01','11:11:11' union all
    select '2010-06-01','11:!1:11'
    --------------开始查询--------------------------
    select convert(varchar(4),[addtime],120) as addtime from [tb]  group by [addtime]
    ----------------结果----------------------------
    /**/
      

  5.   

    select distinct year(addtime) as [我想查出] from tb