标签:
1、简单查询
1.1 查询全部列
Example: select * from t_userInfo
1.2 查询制定列
Example: select * from userName,passWord from t_userInfo
1.3 查询带计算的列
Example: select age*15 from t_userinfo
2、条件查询
1、比较运算符
>、>=、=、<=、<、<>、!>、!< 大小比较
select age from t_userinfo where age<=30 and age>0
2、范围运算符
select * from t_userinfo where age between 1 and 30
3、列表运算符
select * from t_userinfo where type in(‘高级会员‘,‘白金会员‘) //查询会员等级是高级和白金的 select * from t_userinfo where type not in(‘普通会员‘) //查询不是普通会员
4、逻辑运算符
select * from t_userinfo where age>20 and type=‘高级会员‘ select * from t_userinfo where age>20 and type in(‘高级会员‘)
5、空值运算符
select * from t_userinfo where username is null select * from t_userinfo where username is not null
6、模式运算符
% 匹配任意类型和长度的字符。例如A%,表示以A开头的任意长度的字符串
_ 匹配任意单个字符。例如A_B,表示以A开头,以B结尾的长度为3的字符串
[] 用户指定范围,例如[a-h],表示a~h范围内的任意单个字符
[^] 用户指定范围,例如[^a~h],表示a~h范围以外的任意单个字符
select * from t_userinfo where username like ‘%元%‘ select * from t_userinfo where UserName like ‘a____‘ //查询以a开头 长度为5的字母。比如admin
标签:
原文地址:http://my.oschina.net/0x4ad/blog/414208