有一个表如下所示:table 表id name date
1 anne 2005-09-12 00:00:00.000
2 winnie 2005-10-01 00:00:00.000
3 annea 2005-09-09 00:00:00.000
4 wine 2005-10-06 00:00:00.000现在得出其date为 2005-09 的纪录,这条SQL要怎么写?请教各位!
1 anne 2005-09-12 00:00:00.000
2 winnie 2005-10-01 00:00:00.000
3 annea 2005-09-09 00:00:00.000
4 wine 2005-10-06 00:00:00.000现在得出其date为 2005-09 的纪录,这条SQL要怎么写?请教各位!
select * from tableName
where date like '2005-09%'
可以其他函数不是很清楚,好像不同的数据库有不同的操作方式
where left(date,7)='09 2005'
from table
where datediff(month,date,'2005-9-1')=0;9-1还可以是9月1~31任意值。
或
select * from anne where substring(convert(varchar(10),[date],120),6,2)='09'
select * from tableName
where date='2005-09'
where date>='2005-09-01' and date<='2005-09-31'
select * from tableName
where date>='2005-09-01' and date<'2005-09-31'
where date>='2005-09-01' and date<='2005-09-30'