简单相同查询,查询age=22的三列信息,并按照降序排列
SELECT username,weight,age FROM userinfo WHERE age=22 ORDER BY weight DESC
此外,where还支持一下判断操作符
值得注意的是,如果比较的值为数值,则不需要加引号,如果是字符,则需要添加引号(限定引号)
SELECT username,weight,age FROM userinfo WHERE username=‘李明’ ORDER BY weight DESC
BETWEEN查询某个范围的值(中间用and),两边闭区间
SELECT username,weight,age FROM userinfo WHERE age BETWEEN 20 AND 25
一下两个语句效果一样
SELECT username,weight,age FROM userinfo WHERE age>=20 AND age<=25
IS NULL查询 值为空的信息(不是0)
SELECT username,weight,age FROM userinfo WHERE age IS NULL
高级检索
and、or 和与或
SELECT username,weight,age FROM userinfo WHERE age>=20 AND age<=25
SELECT username,weight,age FROM userinfo WHERE age<=20 OR age>=25
值得注意的是:and 和or是可以组合使用的。但在组合是 sql语句优先处理and,后处理or。因此,处理时最好加()消除歧义
IN(相当于OR)
SELECT username,weight,age FROM userinfo WHERE age IN(20,25)
NOT(否定后面的)
SELECT username,weight,age FROM userinfo WHERE NOT age in(20,25,26)