请问date型变量为2010-07-01类型,我想把date型变量的年取利用下面的语句
select * from xx where SUBSTR(DATE_FORMAT(date,'%Y-%m-%d'),0,4)='2010'
来提取某一年的数据但是没有成功,请问应该怎么写?
截取字符串错了,应该是:select * from xx where SUBSTR(DATE_FORMAT(date,'%Y-%m-%d'),1,4)='2010'
你再试试看、
用between应该可以的吧,在2010-01-01 至 2010-12-31就可以了
select * from A t where substr(to_char(t.creattime,'yyyy-MM-dd'),0,4)='2010'
如果字段creattime字段为date类型的就这样,如果不是的话在转换下类型就可以了。