WHERE 常用字句

WHERE 字句
     a) Select*from bbs_user where password=123 and age=21;
     	1. 查询出年龄为21的 并且密码为123的用户 
     b) Select*from bbs_user where password=123 or age=21;
        1. 查询出年龄为21的	或者密码为123的用户 
     C) Select*from bbs_user where age!=21;
	    1. 查询出年龄不为21的 
	 d) Select*from bbs_user where age is null;
	    1. 查询出没有填写年龄字段的用户 
	 e) Select*from bbs_user where age is not null;
	    1. 查询出年龄不为空的用户 
	 f) Select*from bbs_user where age>21 and age<=30;
	    1. 查询出年龄在21到30之间的用户到30之间的用户
	 g) Select*from bbs_user where age between 21 and 30; 
	    1. 同上 
	 h) Select*from bbs_user where age not between 21 and 30;
	    1. 查询出年龄不在21岁到30岁之间的用户
	 i) Select*from bbs_user where username like "zhang%";
	    1. 查询出姓张的用户 %代表通配符 代表的意思是任意个任意字符 
		2. _代表一个任意字符
	 j) Select*from bbs_user where username not like'zhang%';
	    1. 查询出不姓张的用户 
	 K) Select*from bbs_user where id in(1,3,5) ;
	    1. 查询出id为1,3,5,7的用户 
		2. 等价于 id=1 or id=3 or id=5 or id=7
		

猜你喜欢

转载自blog.csdn.net/feiyucity/article/details/84495420