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])
(
[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])
但对日期列进行了相关的函数操作后,建立在时间列上的索引是不起作用的!
但要满足要求,这样写可以接受
建议把你的这个查询做成视图,在视图中这个日期字段建char(8)