+ -
当前位置:首页 → 问答吧 → 新手……问关于SQL模糊查询语句

新手……问关于SQL模糊查询语句

时间:2011-12-06

来源:互联网

select count(字段) from 表名where 字段名like '%条件%’
想查询出这张表里面1月2月的数据,数据是xxxx年x月x日!!!
求模糊查询出这张表1月2月的所有数据!谢谢

作者: wympeter   发布时间: 2011-12-06

你的意思是说你的日期用了字符串来存?

作者: p2227   发布时间: 2011-12-06

SQL code

create table tb
(id int,shijian nvarchar(10))

insert into tb
select 1,'2011年1月2日' union all
select 2,'2010年1月2日' union all
select 3,'2010年1月3日' 

select * From tb where shijian like '____年1月2日'

作者: koumingjie   发布时间: 2011-12-06

SQL code
select *  from 表名
where 字段名 like '%月’

作者: sxssg   发布时间: 2011-12-06

SQL code

select * from 表名 where 日期字段 between '2011-01-01' and '2011-02-29'

作者: pengxuan   发布时间: 2011-12-06

引用 1 楼 p2227 的回复:
你的意思是说你的日期用了字符串来存?

对的!上面的好像都不对!

作者: wympeter   发布时间: 2011-12-06

SQL code
select count(*) from 表名 where 字段名 like '%年1月%' or 字段名 like '%年2月%'

作者: qianjin036a   发布时间: 2011-12-06

SQL code
create table tb(dt nvarchar(12))
insert into tb select '2010年5月9日'
insert into tb select '2010年12月11日'
insert into tb select '2010年1月1日'  --1
insert into tb select '2011年2月15日' --2
insert into tb select '2012年5月22日'
insert into tb select '2011年11月14日'
go
select count(*) from tb where dt like '%年1月%' or dt like '%年2月%'
/*

-----------
2

(1 行受影响)

*/
go
drop table tb

作者: qianjin036a   发布时间: 2011-12-06