当前位置:网站首页>SQL daily exercise - niuke.com
SQL daily exercise - niuke.com
2022-06-13 12:33:00 【EbowTang】
The purpose of this article is :
It's about being right SQL After systematic learning , Conduct :
1, routine , To consolidate ;
2, To deepen the SQL Knowledge system ;
3, summary SQL Related knowledge ;
4, Or one day I can pick up the relevant items quickly SQL knowledge .
Long term update and summary ...... No deadline
Catalog
The purpose of this article is :
SQL3 Query result de duplication
SQL4 Query results limit the number of rows returned
The following are all exercises of niuke.com -mysql Database test results :
SQL1 Query all columns
subject : Now the operator wants to view all the data in the user information table , Please take out the corresponding results
Example :user_profile
id | device_id | gender | age | university | province |
1 | 2138 | male | 21 | Peking University, | Beijing |
2 | 3214 | male | Fudan University | Shanghai | |
3 | 6543 | female | 20 | Peking University, | Beijing |
4 | 2315 | female | 23 | Zhejiang University | ZheJiang |
5 | 5432 | male | 25 | Shandong University | Shandong |
According to the example , Your query should return the following results :
id | device_id | gender | age | university | province |
1 | 2138 | male | 21 | Peking University, | Beijing |
2 | 3214 | male | Fudan University | Shanghai | |
3 | 6543 | female | 20 | Peking University, | Beijing |
4 | 2315 | female | 23 | Zhejiang University | Zhejiang |
5 | 5432 | male | 25 | Shandong University | Shandong |
Example 1
Input :
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); INSERT INTO user_profile VALUES(1,2138,'male',21,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ','Shanghai'); INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ','ZheJiang'); INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ','Shandong');
Copy output :
1|2138|male|21| Peking University, |BeiJing 2|3214|male|None| Fudan University |Shanghai 3|6543|female|20| Peking University, |BeiJing 4|2315|female|23| Zhejiang University |ZheJiang 5|5432|male|25| Shandong University |Shandong
select * from user_profile;
perhaps
select
id,device_id,
gender,
age,
university,province
from user_profile;
SQL2 Query multiple columns
subject : Now, the students want to operate the user's equipment id The corresponding gender 、 Data on age and school , Please take out the corresponding data
Example :user_profile
id | device_id | gender | age | university | province |
1 | 2138 | male | 21 | Peking University, | Beijing |
2 | 3214 | male | Fudan University | Shanghai | |
3 | 6543 | female | 20 | Peking University, | Beijing |
4 | 2315 | female | 23 | Zhejiang University | Zhejiang |
5 | 5432 | male | 25 | Shandong University | Shandong |
According to the example , Your query should return the following results
device_id | gender | age | university |
2138 | male | 21 | Peking University, |
3214 | male | Fudan University | |
6543 | female | 20 | Peking University, |
2315 | female | 23 | Zhejiang University |
5432 | male | 25 | Shandong University |
Example 1
Input :
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); INSERT INTO user_profile VALUES(1,2138,'male',21,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ','Shanghai'); INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ','ZheJiang'); INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ','Shandong');
Copy output :
2138|male|21| Peking University, 3214|male|None| Fudan University 6543|female|20| Peking University, 2315|female|23| Zhejiang University 5432|male|25| Shandong University
select device_id,gender,age,university
from user_profile;
SQL3 Query result de duplication
subject : Now the operation needs to check which schools users come from , Please take the school's de duplication data from the user information table .
Example :user_profile
id | device_id | gender | age | university | province |
1 | 2138 | male | 21 | Peking University, | Beijing |
2 | 3214 | male | Fudan University | Shanghai | |
3 | 6543 | female | 20 | Peking University, | Beijing |
4 | 2315 | female | 23 | Zhejiang University | ZheJiang |
5 | 5432 | male | 25 | Shandong University | Shandong |
According to the example , Your query should return the following results :
university |
Peking University, |
Fudan University |
Zhejiang University |
Shandong University |
Example 1
Input :
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); INSERT INTO user_profile VALUES(1,2138,'male',21,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ','Shanghai'); INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ','ZheJiang'); INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ','Shandong');
Copy output :
Peking University, Fudan University Zhejiang University Shandong University
select distinct university
from user_profile;
perhaps
SELECT university
from user_profile
GROUP BY university;
SQL4 Query results limit the number of rows returned
subject : Now the operation only needs to check the front 2 User details equipment ID data , Please read the user information form user_profile Take out the corresponding results .
Example :
id | device_id | gender | age | university | province |
1 | 2138 | male | 21 | Peking University, | Beijing |
2 | 3214 | male | Fudan University | Shanghai | |
3 | 6543 | female | 20 | Peking University, | Beijing |
4 | 2315 | female | 23 | Zhejiang University | ZheJiang |
5 | 5432 | male | 25 | Shandong University | Shandong |
According to input , Your query should return the following results :
device_id |
2138 |
3214 |
Example 1
Input :
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); INSERT INTO user_profile VALUES(1,2138,'male',21,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ','Shanghai'); INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ','BeiJing'); INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ','ZheJiang'); INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ','Shandong');
Copy output :
2138 3214
select device_id from user_profile limit 2;
select device_id from user_profile limit 0,2;
select device_id from user_profile limit 2 offset 0;
select device_id from user_profile where id in(1,2);
select device_id from user_profile where id <=2;
select device_id from user_profile where id=1 or id=2;
边栏推荐
- OpenCV学习笔记(二):读取mnist数据集
- 婴儿EEG数据的多元模式分析(MVPA):一个实用教程
- About Baseline Models
- The industry-leading interface component package devaxpress officially released v21.2.8 in June
- Cvpr2022 | a convnet for the 2020s & how to design neural network Summary
- 002. Torchserve calls the official library model
- 面试突击56:聚簇索引和非聚簇索引有什么区别?
- mysql中max_connections与max_user_connections使用区别
- 亚信安全陷解约校招生风波:违约金仅3000元 律师称企业需赔偿合理费用
- Lucene from introduction to practice
猜你喜欢
堆排序(heapsort)与比较器
Analysis of DuPont analysis method: financial analysis of the New Retail Group Co., Ltd
SMS based on stm32f103+as608 fingerprint module +4x4 matrix key +sim900a - intelligent access control card system
M1 体验win11
A practice of sharing applet configuration
That is to say, it launched the industry's first data stream recording PAAS scheme, which can reproduce the recording capacity of large manufacturers at low cost
8、DeepFM介绍
Camunda timer events example demo (timer events)
Interview shock 56: what is the difference between clustered index and non clustered index?
HEAPSORT and comparer
随机推荐
想发自己的NFT,你要先搞清楚这6个问题
Camunda timer events example demo (timer events)
我想转行程序员,上个编程培训班,能找到工作吗?我可以自学吗?
client offset scroll 之间的区别
Best practices for SaaS application architecture
Cesium 之实现鹰眼功能(可拖拽矩形框定位范围)
如何基于Ceph设计与构建一套软件定义存储系统
Fast platoon and Dutch flag
(转载)Multi-Context CoreData 之多线程环境中使用CoreData
构建一个安全的云平台
004. Torchserve calls LR two category prediction
浅谈常见的web攻击以及如何防范
云安全服务的选择
一切的开始,测试学妹
MIT 发现苹果 M1 中新型硬件漏洞:可不留痕迹攻破安全机制
The answer to the subject of "Regulations" of the second construction company in 2022 has been provided. Please keep it
The answer to the subject "highway" of the second construction company in 2022 has been provided. Please keep it
How to quickly SAA traditional applications at the minimum cost
004、torchserve 调用LR二分类预测
“躺着都能赚钱”的时代已经过去,亚马逊云科技为跨境电商找到下一个爆点