题解 | #查找除复旦大学的用户信息#

几种方法:

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 = "复旦大学") 

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 14:35
点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务