to: zhuzhichao(炎龙骑士团—索尔—破龙击) 这样不能用索引,不好,应这样,能用索引 select * from table where date>='2002-03-09' and date<'2002-03-10'
select * from table where date >= '2001-01-01' and date<'2001-01-02'
可以这样: select * from table where convert(varchar(10),date,120) = '2001-01-01' 但是,若在date字段上有索引的的话,那么将用不到索引 还可以这样 select * from table where date >= '2001-01-01' and date<'2001-01-02' 若在date字段上有索引的的话,可以用到索引
你的时分秒是因为你写入的是time,而你想凭时间查询,最好的方法就是用select * from table where date between '2001-01-01' and '2001-01-02' 这样最有效率。
select xmlContent from pus where status = 9999999 and convert(varchar(10),receivedTime,120) = '2001-01-01' 我这样写不可以么? 怎么查不到结果呢? 我还想问一下,哪个120是什么意思?
这样不能用索引,不好,应这样,能用索引
select * from table where date>='2002-03-09' and date<'2002-03-10'
select * from table where convert(varchar(10),date,120) = '2001-01-01'
但是,若在date字段上有索引的的话,那么将用不到索引
还可以这样
select * from table where date >= '2001-01-01' and date<'2001-01-02'
若在date字段上有索引的的话,可以用到索引
这样最有效率。
怎么查不到结果呢?
我还想问一下,哪个120是什么意思?
convert(char(10),列名,120)
between '2001-01-01' and '2001-01-02'
等于 date >= '2001-01-01' and date<='2001-01-02'
把等于'2001-01-02' 的记录也找出来了,不对。