create table table1
(
    [id]     int           identity, 
    title    nvarchar(100) not null, 
    content  ntext         not null, 
    [date]   datetime      not null default getdate()
)create clusterd index ix1
on table1 ([date] desc)create unique nonclusterd index ix2
on table1 ([id])SELECT YEAR([date]) AS 年, MONTH([date]) AS 月, DAY([date]) AS 日
FROM dbo.table1
GROUP BY YEAR([date]), MONTH([date]), DAY([date])

解决方案 »

  1.   

    如果要把 year, month, day合起来呢?
      

  2.   

    select convert(varchar, [date], 110) as 日期, count(id) as 数量 from table1 group by convert(varchar, [date], 110)楼主的这种写法比一楼的效率还高些!
    但对日期列进行了相关的函数操作后,建立在时间列上的索引是不起作用的!
    但要满足要求,这样写可以接受
      

  3.   

    使用函数,sql只能使用遍历,所以效率奇低;按你的意思不如就再用一个字段存储smalldate的信息
      

  4.   

    可以强制索引试试,
    建议把你的这个查询做成视图,在视图中这个日期字段建char(8)