sql server 2005 (select查询语句用法)

select * from userInfo where age like '2[25]'

功能:查询userInfo表中age字段,所有以2开头,且第二位是2或5的记录。

 

select * from userInfo where name like '_娜_'

功能:查询userInfo表中name(char(6))字段所有中间一个字是“娜”的记录。下划线“_”代表的是两个任意字符,如上:名为“谢娜娜”或“谢娜”等的记录将会被查询出来

 

select * from userInfo where address like '%川%'

功能:查询userInfo表中address字段所有包含“川”字的记录

 

select * from userInfo where name like '[m-n]%'

功能:查询所有userInfo表中所有name字段是以m或n开头的记录

 

select * from userInfo where name like 'm[^i]%'

功能:查询userInfo表中name字段所有以m开头、第2个字母不是字母c的名称

 

select * from userInfo where ID in(1,2)

功能:查询userInfo表中所有ID等于1或者2的记录

等同于

select * from userInfo where ID='1' or ID='2'

 

select * from userInfo where memo like '20/%' escape '/'

功能:查询memo字段值为20%的所有记录,但是在sql Server里面%为通配符如果不加就会有其他意思

例如:select * from userInfo where memo like '2%'   就跟上面查到一样的记录,这一句的功能是查到memo字段的值以2开头的记录。20%也是以2开头的。这样就会出现问题。所以用转义字符还是很必要的。

 

select count(distinct ProdID) '产品种类' from userInfo

功能:查询出来有多少种产品,distinct就是查询不重复的记录,加上count()就是不重复的记录的总数了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值