当前位置:网站首页>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 !!!
边栏推荐
- How does the vditor renderer achieve server-side rendering (SSR)?
- Leetcode notes 118. Yang Hui triangle
- 【架构】评分较高的三本微服务书籍的阅读笔记
- 功率放大器和匹配网络学习
- Cool operation preheating! Code to achieve small planet effect
- Debezium系列之:2.0.0.Beta1的重大变化和新特性
- [ecmascript6] function and its related use
- C language: random generated number + merge sort
- 数据库系统原理与应用教程(059)—— MySQL 练习题:操作题 1-10(三)
- 微信小程序中自定义模板
猜你喜欢

Some thoughts on.Net desktop development

国产API管理工具Eolink太好用了,打造高效的研发利器

MySQL practice -- master-slave replication

《如何打一场数据挖掘赛事》入门版

Leetcdoe-342. Power of 4

Humiliation, resistance, reversal, 30 years, China should win Microsoft once

【安全】 阅读 RFC6749 及理解 Oauth2.0 下的授权码模式

Chapter 6 promotion

微念“失去”李子柒的这一年

Why is crypto game changing the game industry?
随机推荐
jar包
Use non recursive method to realize layer traversal, preorder traversal, middle order traversal and post order traversal in binary tree
C语言学生成绩管理系统详解[通俗易懂]
LyScript 获取上一条与下一条指令
kotlin学习笔记3——Lambda编程
力扣 2354. 优质数对的数目
Go language - Application of stack - expression evaluation
Basic exercises of DQL in MySQL
从手机厂高位“出走”的三个男人
屈辱、抗争、逆转,三十年,中国该赢微软一次了
《如何打一场数据挖掘赛事》入门版
Parent and child of treeselect
Facial expression recognition based on pytorch convolution - graduation project "suggestions collection"
.NET桌面开发的一些思考
Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022
FFT wave simulation
powerdesigner创建数据库模型(概念模型举例)
Continuous (integration -- & gt; delivery -- & gt; deployment)
Why is crypto game changing the game industry?
沾上趣店,都得道歉?
