【牛客刷题--SQL篇】SQL9查找除复旦大学的用户信息&&SQL10用where过滤空值练习_现在运营想要查看除复旦大学以外的所有用户明细,请你取出相应数据(2)

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

输入:
drop table if exists user_profile;
CREATE TABLE user\_profile (
id int NOT NULL,
device\_id int NOT NULL,
gender varchar(14) NOT NULL,
age int ,
university varchar(32) NOT NULL,
province varchar(32) NOT NULL);
INSERT INTO user_profile VALUES(1,2138,‘male’,21,‘北京大学’,‘BeiJing’);
INSERT INTO user_profile VALUES(2,3214,‘male’,null,‘复旦大学’,‘Shanghai’);
INSERT INTO user_profile VALUES(3,6543,‘female’,20,‘北京大学’,‘BeiJing’);
INSERT INTO user_profile VALUES(4,2315,‘female’,23,‘浙江大学’,‘ZheJiang’);
INSERT INTO user_profile VALUES(5,5432,‘male’,25,‘山东大学’,‘Shandong’);

输出:
2138|male|21|北京大学
6543|female|20|北京大学
2315|female|23|浙江大学
5432|male|25|山东大学


![在这里插入图片描述](https://img-blog.csdnimg.cn/f74bdcc54a71478f891617881dd1c783.png)


#### 1.1.1 SQL语句 第一种方法(执行效率略高)



> 
> select  
>  device\_id,  
>  gender,  
>  age,  
>  university  
>  from  
>  user\_profile  
>  where  
>  university != ‘复旦大学’
> 
> 
> 



select
device_id,
gender,
age,
university
from
user_profile
where
university != ‘复旦大学’


![在这里插入图片描述](https://img-blog.csdnimg.cn/6f75411823474f52af6599617865ba8e.png)  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/60b35a56f2b24ecba78701137465f9e6.png)


#### 1.1.2 SQL语句 第二种方法(执行效率略低)



> 
> select  
>  device\_id,  
>  gender,  
>  age,  
>  university  
>  from  
>  user\_profile  
>  where  
>  university <> ‘复旦大学’
> 
> 
> 



select
device_id,
gender,
age,
university
from
user_profile
where
university <> ‘复旦大学’


![在这里插入图片描述](https://img-blog.csdnimg.cn/c584a50f26754894946db936d9c4f114.png)  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/79a95c98fca94c8aa00fab02ef237ad1.png)


### 1.2 SQL10 用where过滤空值练习


* 描述  
 题目:现在运营想要对用户的年龄分布开展分析,在分析时想要剔除没有获取到年龄的用户,请你取出所有年龄值不为空的用户的设备ID,性别,年龄,学校的信息。  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/ae43844be560473f96c7b54a9b83e42c.png)
* 示例1



> 
> **输入**:  
>  drop table if exists user\_profile;  
>  CREATE TABLE `user_profile` (  
>  `id` int NOT NULL,  
>  `device_id` int NOT NULL,  
>  `gender` varchar(14) NOT NULL,  
>  `age` int ,  
>  `university` varchar(32) NOT NULL,  
>  `province` varchar(32) NOT NULL);  
>  INSERT INTO user\_profile VALUES(1,2138,‘male’,21,‘北京大学’,‘BeiJing’);  
>  INSERT INTO user\_profile VALUES(2,3214,‘male’,null,‘复旦大学’,‘Shanghai’);  
>  INSERT INTO user\_profile VALUES(3,6543,‘female’,20,‘北京大学’,‘BeiJing’);  
>  INSERT INTO user\_profile VALUES(4,2315,‘female’,23,‘浙江大学’,‘ZheJiang’);  
>  INSERT INTO user\_profile VALUES(5,5432,‘male’,25,‘山东大学’,‘Shandong’);
> 
> 
> 



> 
> **输出**:  
>  2138|male|21|北京大学  
>  6543|female|20|北京大学  
>  2315|female|23|浙江大学  
>  5432|male|25|山东大学
> 
> 
> 



输入:
drop table if exists user_profile;
CREATE TABLE user\_profile (
id int NOT NULL,
device\_id int NOT NULL,
gender varchar(14) NOT NULL,
age int ,
university varchar(32) NOT NULL,
province varchar(32) NOT NULL);
INSERT INTO user_profile VALUES(1,2138,‘male’,21,‘北京大学’,‘BeiJing’);
INSERT INTO user_profile VALUES(2,3214,‘male’,null,‘复旦大学’,‘Shanghai’);
INSERT INTO user_profile VALUES(3,6543,‘female’,20,‘北京大学’,‘BeiJing’);
INSERT INTO user_profile VALUES(4,2315,‘female’,23,‘浙江大学’,‘ZheJiang’);
INSERT INTO user_profile VALUES(5,5432,‘male’,25,‘山东大学’,‘Shandong’);

输出:
2138|male|21|北京大学
6543|female|20|北京大学
2315|female|23|浙江大学
5432|male|25|山东大学


![在这里插入图片描述](https://img-blog.csdnimg.cn/90b8f48c88e245e9ae5e97ad84ea8047.png)


#### 1.2.1 SQL语句 第一种方法(执行效率略低)



> 
> select  
>  device\_id,  
>  gender,  
>  age,  
>  university  
>  from  
>  user\_profile  
>  where  
>  age != ’ ’
> 
> 
> 



select
device_id,
gender,
age,
university
from
user_profile
where
age != ’ ’


![在这里插入图片描述](https://img-blog.csdnimg.cn/4f67b609c5f94bf3be357a3ff530274b.png)  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/bc0887608ded4ba2a71896b6d7f84b28.png)


#### 1.2.2 SQL语句 第二种方法(执行效率略高)



> 
> select  
>  device\_id,  
>  gender,  
>  age,  
>  university  
>  from  
>  user\_profile  
>  where  
>  age <> ’ ’
> 
> 
> 



select
device_id,
gender,
age,
university
from
user_profile
where
age <> ’ ’

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

aiAHUsf-1715369824784)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

  • 20
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值