欢迎来到石家庄建站小程序开发公司

数据库

从表中取出某年或某月的数据

作者: 发布时间:2010-11-03 点击:

select * from table1 where month(convert(varchar(10),btime,112))=9    //取出9月的数据

select year(convert(varchar(10),getdate(),120))     //得到当前的年份

select month(convert(varchar(10),btime,120)) from table1   //得到当前表数据的月份

select * from table1 where month(convert(varchar(10),btime,120))=3   //取出3月份的数据

在上面语句中,btime字段需要是日期格式

新闻资讯
相关案例