题解 | #查找除复旦大学的用户信息#
几种方法:
1、直接where条件语句用 !=
select device_id,gender,age,university
from user_profile
where university!="复旦大学";
2、直接where条件语句用 not in()
select device_id,gender,age,university
from user_profile
where university not in ("复旦大学");
语法举例
1)查询 city 表中 ID 不是在10~100之间的所有值。
SELECT ID
FROM city
WHERE ID NOT IN(
SELECT ID
FROM city
WHERE ID > 11 AND ID < 100);
2)查询 city 表中 ID 除 10 和 100 之外的所有值。
SELECT ID
FROM city
WHERE ID NOT IN(10,100);
3、<> 运算符
作用:表示不等于。
说明:和 “!=” 运算符的作用一致,相较之下 “<>” 的可读性较差。
select device_id,gender,age,university
from user_profile
where university <> '复旦大学';
4、not 运算符:否定它之后所跟的任何条件。 注意和第二种not in 之间的区别
SELECT `device_id`,`gender`,`age`,`university`
from user_profile
where not (university = "复旦大学")