当前位置:网站首页>SQL daily practice (Niuke new question bank) - day 4: advanced operators
SQL daily practice (Niuke new question bank) - day 4: advanced operators
2022-07-28 13:44:00 【No envy】
List of articles
1. Advanced operator exercises (2)
subject : Now I want to find a school for Peking University or GPA stay 3.7 above ( barring 3.7) Conduct research on users , Please take out the relevant data ( Use OR Realization )
Create table statement :
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,' Peking University, ','BeiJing',3.4);
INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ','Shanghai',4.0);
INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ','BeiJing',3.2);
INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ','ZheJiang',3.6);
INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ','Shandong',3.8);
The answer is :
SELECT
device_id,
gender,
age,
university,
gpa
FROM
user_profile
WHERE
gpa > '3.7'
OR
university = ' Peking University, '

2. Where in and Not in
subject : Now I want to find a school for Peking University 、 Students from Fudan University and Shanda University conducted research , Please take out the relevant data .
Create table statement :
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,' Peking University, ','BeiJing',3.4);
INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ','Shanghai',4.0);
INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ','BeiJing',3.2);
INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ','ZheJiang',3.6);
INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ','Shandong',3.8);
The answer is :
select device_id,gender,age,university,gpa
from user_profile
WHERE university=" Peking University, " or university=" Fudan University " or university=" Shandong University "

3. Operators mix
subject : Now I want to find gpa stay 3.5 above ( barring 3.5) Shandong University Users or gpa stay 3.8 above ( barring 3.8) Students from Fudan University conducted User Research , Please take out the corresponding data

Create table statement :
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,' Peking University, ','BeiJing',3.4);
INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ','Shanghai',4.0);
INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ','BeiJing',3.2);
INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ','ZheJiang',3.6);
INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ','Shandong',3.8);
The answer is :
SELECT device_id, gender, age, university,gpa from user_profile where gpa > 3.8 and university = ' Fudan University ' UNION
SELECT device_id, gender, age, university,gpa from user_profile where gpa > 3.5 and university = ' Shandong University '

4. View users with Beijing in the school name
subject : Now the operator wants to view the information of users with Beijing in all universities , Please take out the corresponding data .
Create table statement :
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,' Peking University, ',3.4);
INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ',4.0);
INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ',3.2);
INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ',3.6);
INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ',3.8);
INSERT INTO user_profile VALUES(6,2131,'male',28,' Beijing Normal University ',3.3);
The answer is :
select device_id,age,university
from user_profile
-- where university like '% Beijing %';
WHERE university regexp " Beijing ";
-- Regular expressions are used to match special strings of text ( Character set )( Matching text , Put a pattern ( Regular expressions ) Compare with a text string ).
-- LIKE and REGEXP Important differences between
-- LIKE Match the entire column , If the matched text appears in the column value ,LIKE It will not be found , The corresponding row is not returned ( Unless you use wildcards ). and REGEXP Match within column values , If the matched text appears in the column value ,REGEXP It will be found , The corresponding line is returned , also REGEXP Can match the entire column value ( And LIKE Same effect ).

5. How to make question brushing more efficient ?
Recently, many kids who have learned the basics asked me how to improve my programming level ? What should I do after learning the basics ? Mingming learned a lot , Do the project but don't know how to get started , In fact, this is too little practice , Only pay attention to learning , But ignore the question , Only continuous practice can improve and consolidate programming thinking and ability !
Link address : Cattle from | SQL Brush topic , Stop talking nonsense and speed up !!!
边栏推荐
- 111. SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误
- C language: random number + quick sort
- vim常用命令详解(vim使用教程)
- Night God simulator packet capturing wechat applet
- C language: random generated number + merge sort
- Better and more modern terminal tools than xshell!
- Excellent performance! Oxford, Shanghai, AI Lab, Hong Kong University, Shangtang, and Tsinghua have joined forces to propose a language aware visual transformer for reference image segmentation! Open
- LyScript 获取上一条与下一条指令
- How does the vditor renderer achieve server-side rendering (SSR)?
- Paddleclas classification practice record
猜你喜欢

蓝桥集训(附加面试题)第七天

Map tiles: detailed explanation of vector tiles and grid tiles

Auto.js enables Taobao to quickly submit orders

倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展

今日睡眠质量记录75分

ES6 null merge operator (?)

Three men "running away" from high positions in the mobile phone factory

Parent and child of treeselect

Night God simulator packet capturing wechat applet

Unity - "synthetic watermelon" small game notes
随机推荐
Rust from introduction to mastery 01 introduction
用非递归的方法实现二叉树中的层遍历,先序遍历,中序遍历和后序遍历
数据库系统原理与应用教程(062)—— MySQL 练习题:操作题 32-38(六)
JS encapsulation at a glance
Parent and child of treeselect
C语言:顺序存储结构的快速排序
Three men "running away" from high positions in the mobile phone factory
【C语言】结构体指针与结构体变量作形参的区别
如何配置adb环境变量(环境变量在哪打开)
I miss the year of "losing" Li Ziqi
Debezium系列之:2.0.0.Beta1的重大变化和新特性
Rust 从入门到精通01-简介
nport串口服务器配置网址(串口服务器是不是网口转串口)
Half wave rectification light LED
少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
Go language - Application of stack - expression evaluation
Leetcdoe-342. Power of 4
DDoS protection with iptables
Blue Bridge Training (additional interview questions) day 7
Leetcode-190. inverting binary bits
