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()就是不重复的记录的总数了

上一篇: 揭秘Android 9核心破解:安全风险与应对策略全解析
下一篇: Watch the latest 鬼怪 Episode 1 online with English subtitle for free – iQIYI

相关推荐

行星际磁场
春季适合喝的10种养生粥食谱 春天喝什么粥养生效果好→MAIGOO生活榜
古希腊时代,斯巴达为何要将不健康的新生婴儿随意丢弃?
正版平价洛丽塔洋装Lolita店铺推荐17家,人气淘宝店来一波!
昆明已经有3种共享汽车啦!怎么租车?哪个更划算?快看看!
虎牙女主播排名及人气分析,虎牙最火女主播是谁