cheng029 发表于 2012-8-21 13:23:11

select查询语句用法

select * from userInfo where age like '2'
功能:查询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 '%'
功能:查询所有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()就是不重复的记录的总数了

cheng029 发表于 2012-8-21 13:23:19

这个帖子不错,大家快来顶起来!

cheng029 发表于 2012-8-21 13:23:30

{:6_407:}

sxz6024 发表于 2012-8-27 08:47:29

{:6_394:}不错不错{:6_432:}

tyxiayu 发表于 2013-5-15 17:16:53

没看完~~~~~~ 先顶,好同志

nawawa001 发表于 2013-5-17 05:48:14

爱护环境,人人有病。

sxyzy 发表于 2013-5-18 12:26:00

过来看看的
页: [1]
查看完整版本: select查询语句用法