💖个人主页:@与自己作战
💯作者简介:大数据领域优质创作者、CSDN@内容合伙人、阿里云专家博主
💞牛客刷题系列篇:【SQL篇】】【Python篇】【Java篇】
📌推荐刷题网站注册地址:【牛客网–SQL篇】
💘推荐理由:从0-1起步,循序渐进
🆘希望大佬们多多支持,携手共进
📝 如果文章对你有帮助的话,欢迎评论💬点赞👍收藏📂加关注
⛔如需要支持请私信我,💯必支持
👩👩👦👦网址注册地址:【牛客网–注册地址】👩👩👦👦
文章目录
一、条件查询
1、高级操作符
1.1、SQL14 操作符混合运用
- 描述
题目:现在运营想要找到gpa在3.5以上(不包括3.5)的山东大学用户 或 gpa在3.8以上(不包括3.8)的复旦大学同学进行用户调研,请你取出相应数据
- 示例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,
gpa
float);
INSERT INTO user_profile VALUES(1,2138,‘male’,21,‘北京大学’,‘BeiJing’,3.4);
INSERT INTO user_profile VALUES(2,3214,‘male’,null,‘复旦大学’,‘Shanghai’,4.0);
INSERT INTO user_profile VALUES(3,6543,‘female’,20,‘北京大学’,‘BeiJing’,3.2);
INSERT INTO user_profile VALUES(4,2315,‘female’,23,‘浙江大学’,‘ZheJiang’,3.6);
INSERT INTO user_profile VALUES(5,5432,‘male’,25,‘山东大学’,‘Shandong’,3.8);
输出:
3214|male|None|复旦大学|4.0
5432|male|25|山东大学|3.8
输入:
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,
`gpa` float);
INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing',3.4);
INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学','Shanghai',4.0);
INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学','BeiJing',3.2);
INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学','ZheJiang',3.6);
INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学','Shandong',3.8);
复制
输出:
3214|male|None|复旦大学|4.0
5432|male|25|山东大学|3.8
1.1.1、SQL语句(第一种写法)
select
device_id,
gender,
age,
university,
gpa
from
user_profile
where
(
gpa > 3.5
and university = ‘山东大学’
)
or (
gpa > 3.8
and university = ‘复旦大学’
)
select
device_id,
gender,
age,
university,
gpa
from
user_profile
where
(
gpa > 3.5
and university = '山东大学'
)
or (
gpa > 3.8
and university = '复旦大学'
)
1.1.2、SQL语句(第二种写法)
select
device_id,
gender,
age,
university,
gpa
from
user_profile
where
gpa > 3.5
and university = ‘山东大学’
union
select
device_id,
gender,
age,
university,
gpa
from
user_profile
where
gpa > 3.8
and university = ‘复旦大学’
select
device_id,
gender,
age,
university,
gpa
from
user_profile
where
gpa > 3.5
and university = '山东大学'
union
select
device_id,
gender,
age,
university,
gpa
from
user_profile
where
gpa > 3.8
and university = '复旦大学'
1.1.3、SQL语句(第三种写法)
select
device_id,
gender,
age,
university,
gpa
from
user_profile
where
gpa > 3.5
and university = ‘山东大学’
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
14457378178)]
[外链图片转存中…(img-J0sjHSc3-1714457378179)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新