输入:
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|山东大学
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 != '复旦大学'
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 <> '复旦大学'
1.2 SQL10 用where过滤空值练习
- 描述
题目:现在运营想要对用户的年龄分布开展分析,在分析时想要剔除没有获取到年龄的用户,请你取出所有年龄值不为空的用户的设备ID,性别,年龄,学校的信息。
- 示例1
输入:
drop table if exists user_profile;
CREATE TABLEuser_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|山东大学
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 != ' '
1.2.2 SQL语句 第二种方法(执行效率略高)
select
device_id,
gender,
age,
university
from
user_profile
where
age <> ’ ’
select
device_id,
![img](https://img-blog.csdnimg.cn/img_convert/f64bc78f46b9638cee46819587f72814.png)
![img](https://img-blog.csdnimg.cn/img_convert/53d1880a82cb10dcca1b8c4b5c7dd933.png)
![img](https://img-blog.csdnimg.cn/img_convert/32e3421f81ba80996360791161507262.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
存中...(img-9Hp4E1IK-1714177006423)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**