当前位置:网站首页>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 !!!
边栏推荐
- JS method of splitting strings
- 《暗黑破坏神4》PS4/PS5测试版已加入PlayStation数据库
- 屈辱、抗争、逆转,三十年,中国该赢微软一次了
- Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022
- How does the vditor renderer achieve server-side rendering (SSR)?
- FFT wave simulation
- Redis - Basics
- 二舅能治好年轻人的精神内耗吗?
- Jar package
- GO语言-栈的应用-表达式求值
猜你喜欢

Rust from introduction to mastery 01 introduction

基于神经网络的帧内预测和变换核选择

《暗黑破坏神4》PS4/PS5测试版已加入PlayStation数据库

How to check if the interface cannot be adjusted? I didn't expect that the old bird of the 10-year test was planted on this interview question

Volcanic stone investment Zhang Suyang: hard technology, the relatively certain answer in the next 10 years

半波整流点亮LED

Shell basic concepts and variables

二舅能治好年轻人的精神内耗吗?

用非递归的方法实现二叉树中的层遍历,先序遍历,中序遍历和后序遍历

Night God simulator packet capturing wechat applet
随机推荐
什么叫杂谈(e网杂谈)
paddleClas分类实践记录
长封闭期私募产品再现 业内人士看法各异
PHP generates random numbers (nickname random generator)
Why is crypto game changing the game industry?
Half wave rectification light LED
FFT海浪模拟
《暗黑破坏神4》PS4/PS5测试版已加入PlayStation数据库
Unity - "synthetic watermelon" small game notes
【架构】评分较高的三本微服务书籍的阅读笔记
Li Kou sword finger offer 51. reverse order pairs in the array
严格模式——let和const——箭头函数——解构赋值——字符串模板symbol——Set和Map——生成器函数
合并表格行---三层for循环遍历数据
力扣 2354. 优质数对的数目
[dark horse morning post] byte valuation has shrunk to $270billion; "Second uncle" video author responded to plagiarism; Renzeping said that the abolition of the pre-sale system of commercial housing
Rust from introduction to mastery 01 introduction
微信小程序中自定义模板
朋友发来几个面试题
使用 Fail2ban 保护 Web 服务器免受 DDoS 攻击
Shell基础概念和变量
