当前位置:网站首页>SQL每日一练(牛客新题库)——第4天:高级操作符
SQL每日一练(牛客新题库)——第4天:高级操作符
2022-07-28 12:33:00 【无 羡ღ】
1. 高级操作符练习(2)
题目:现在运营想要找到学校为北大或GPA在3.7以上(不包括3.7)的用户进行调研,请你取出相关数据(使用OR实现)
建表语句:
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);
解题答案:
SELECT
device_id,
gender,
age,
university,
gpa
FROM
user_profile
WHERE
gpa > '3.7'
OR
university = '北京大学'

2. Where in 和Not in
题目:现在运营想要找到学校为北大、复旦和山大的同学进行调研,请你取出相关数据。
建表语句:
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);
解题答案:
select device_id,gender,age,university,gpa
from user_profile
WHERE university="北京大学" or university="复旦大学" or university="山东大学"

3. 操作符混合运用
题目:现在运营想要找到gpa在3.5以上(不包括3.5)的山东大学用户 或 gpa在3.8以上(不包括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);
解题答案:
SELECT device_id, gender, age, university,gpa from user_profile where gpa > 3.8 and university = '复旦大学' UNION
SELECT device_id, gender, age, university,gpa from user_profile where gpa > 3.5 and university = '山东大学'

4. 查看学校名称中含北京的用户
题目:现在运营想查看所有大学中带有北京的用户的信息,请你取出相应数据。
建表语句:
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,
`gpa` float);
INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学',3.4);
INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学',4.0);
INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学',3.2);
INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学',3.6);
INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学',3.8);
INSERT INTO user_profile VALUES(6,2131,'male',28,'北京师范大学',3.3);
解题答案:
select device_id,age,university
from user_profile
-- where university like '%北京%';
WHERE university regexp "北京";
-- 正则表达式用来匹配文本的特殊的串(字符集合)(匹配文本,将一个模式(正则表达式)与一个文本串进行比较)。
-- LIKE 和 REGEXP之间的重要差别
-- LIKE 匹配整个列,如果被匹配的文本在列值中出现,LIKE 将不会找到它,相应的行也不会被返回(除非使用通配符)。而 REGEXP 在列值内进行匹配,如果被匹配的文本在列值中出现,REGEXP 将会找到它,相应的行将被返回,并且 REGEXP 能匹配整个列值(与 LIKE 相同的作用)。

5. 如何让刷题变得更高效?
最近很多学了基础的小伙伴问我该怎么提升编程水平?学了基础该上哪刷题?明明学了很多,做项目却不知道怎么上手,其实这就是练得太少,只注重了学,却忽视了刷题,只有不断练习才能提高和巩固编程思维和能力!
链接地址:牛客网 | SQL刷题篇,废话少说速度上号!!!
边栏推荐
- How much do you know about JVM memory management
- Definition of option basis
- Redis —— 基础篇
- Night God simulator packet capturing wechat applet
- [error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088
- Resolve browser password echo
- 二舅能治好年轻人的精神内耗吗?
- Can second uncle cure young people's spiritual internal friction?
- 微信小程序中自定义模板
- Auto.js enables Taobao to quickly submit orders
猜你喜欢

Blue Bridge Training (additional interview questions) day 7

Unity—“合成大西瓜”小游戏笔记

Have you seen the management area decoupling architecture? Can help customers solve big problems

屈辱、抗争、逆转,三十年,中国该赢微软一次了

Bull spread portfolio

gicv3 spi register
![[error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088](/img/81/641a5b3445534fc3b8c87ee6deaa64.png)
[error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088

Some thoughts on.Net desktop development

今日睡眠质量记录75分

管理区解耦架构见过吗?能帮客户搞定大难题的
随机推荐
Le transaction
Leetcode-190. inverting binary bits
Leetcode 笔记 566. 重塑矩阵
倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展
Protobuf data exchange format
[ecmascript6] function and its related use
butterfly spreads
Using auto.js to realize the function of fifaol3 mobile terminal card interceptor
Beyond Istio OSS——Istio服务网格的现状与未来
Redis - Basics
Paddleclas classification practice record
org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
Parent and child of treeselect
Leetcode notes 566. Reshaping the matrix
Single option trading and cross trade
什么叫杂谈(e网杂谈)
Is azvudine, a domestic oral new coronal drug, safe? Expert authority interpretation
Unity - "synthetic watermelon" small game notes
One track education, PHP training, unity of knowledge and practice, popular
jar包
