当前位置:网站首页>Niuke brush sql---2
Niuke brush sql---2
2022-07-26 13:08:00 【Xiao Tang (๑ & gt; & lt; ๑)】
Author's brief introduction : Hello everyone, I'm classmate Tang (๑><๑), You can call me Xiao Tang
Personal home page : Xiao Tang (๑><๑) The blog home page of
Series column : Niuke net brush SQL
If you need to apply for a job or brush questions, you can click the link to register directly , Write the questions together : Click the jump
Niuke network support ACM Mode , It is also recommended to brush algorithm questions !!!
SQL37 Sort multiple columns after searching
describe
subject : Now the operator wants to take out the age and... In the user information table gpa data , And first according to gpa Ascending sort , Then sort the output in ascending order of age , Please take out the corresponding data .
User information sheet :user_profile
| id | device_id | gender | age | university | gpa |
| 1 | 2138 | male | 21 | Peking University, | 3.4 |
| 2 | 3214 | male | 23 | Fudan University | 4 |
| 3 | 6543 | female | 20 | Peking University, | 3.2 |
| 4 | 2315 | female | 23 | Zhejiang University | 3.6 |
| 5 | 5432 | male | 25 | Shandong University | 3.8 |
| 6 | 2131 | male | 28 | Beijing Normal University | 3.3 |
Your query should return the following results :
| device_id | gpa | age |
| 6534 | 3.2 | 20 |
| 2131 | 3.3 | 28 |
| 2138 | 3.4 | 21 |
| 2315 | 3.6 | 23 |
| 5432 | 3.8 | 25 |
| 3214 | 4 | 23 |
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, `gpa` float); INSERT INTO user_profile VALUES(1,2138,'male',21,' Peking University, ',3.4); INSERT INTO user_profile VALUES(2,3214,'male',23,' 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);
Copy output :
6543|3.200|20 2131|3.300|28 2138|3.400|21 2315|3.600|23 5432|3.800|25 3214|4.000|23
select device_id,gpa,age from user_profile order by gpa ,age;SQL38 Sort in descending order after finding
describe
subject : Now the operator wants to retrieve the corresponding data in the user information table , And first according to gpa、 Sort the output in descending order of age , Please take out the corresponding data .
Example user_profile:
| id | device_id | gender | age | university | gpa |
| 1 | 2138 | male | 21 | Peking University, | 3.4 |
| 2 | 3214 | male | 23 | Fudan University | 4 |
| 3 | 6543 | female | 20 | Peking University, | 3.2 |
| 4 | 2315 | female | 23 | Zhejiang University | 3.6 |
| 5 | 5432 | male | 25 | Shandong University | 3.8 |
| 6 | 2131 | male | 28 | Beijing Normal University | 3.3 |
According to the example , Your query should return the following results :
| device_id | gpa | age |
| 3214 | 4 | 23 |
| 5432 | 3.8 | 25 |
| 2315 | 3.6 | 23 |
| 2138 | 3.4 | 21 |
| 2131 | 3.3 | 28 |
| 6543 | 3.2 | 20 |
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, `gpa` float); INSERT INTO user_profile VALUES(1,2138,'male',21,' Peking University, ',3.4); INSERT INTO user_profile VALUES(2,3214,'male',23,' 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);
Copy output :
3214|4.0|23 5432|3.8|25 2315|3.6|23 2138|3.4|21 2131|3.3|28 6543|3.2|20
select device_id, gpa, age from user_profile order by gpa desc,age desc ;Tell you again Niuke is really a good question brush Improve your platform And it is also a platform for job hunting There are special entry experience of each company
I really recommend it to you
It's really recommended that you come to Niuke and brush questions together !!!!!
If you are willing, you can click the link to register and brush the questions together Point me to jump
边栏推荐
- Use positioning to realize left, middle and right layout, and the middle content is adaptive
- 基于WebRTC和WebSocket实现的聊天系统
- The programmed navigation route jumps to the current route (the parameters remain unchanged), and if it is executed multiple times, it will throw a navigationduplicated warning error?
- Mysql数据目录(1)---数据库结构(二十四)
- 一笔画问题(中国邮递员问题)
- 0 basic programming resources (collect first ~ read slowly ~)
- B+树(3)聚簇索引,二级索引 --mysql从入门到精通(十五)
- Detailed explanation of redisson distributed lock process (II)
- Huawei recruited "talented teenagers" twice this year; 5.4 million twitter account information was leaked, with a selling price of $30000; Google fired engineers who believed in AI consciousness | gee
- 基于BERT的情感分析模型
猜你喜欢

Kubernetes APIServer 限流策略

Today's sleep quality record 75 points

The difference between $route and $route

基于ASP.NET的某高校学院档案管理系统

Food safety | can you eat any fruit?

JVM: what does the class loading subsystem do? What is it made of? What eight part essay do you need to remember?

高通再次「押宝」中科创达,挑战智能驾驶软硬件全栈方案

Kubernetes apiserver current limiting strategy

一笔画问题(中国邮递员问题)

V00 - do whatever you want when you are old
随机推荐
被罚“带薪休假”一个月后,谷歌解雇了“爱”上 AI 的他
Mysql数据目录(2)---表数据结构(二十五)
Streamnational team culture: a "transparent" company
JVM: what does the class loading subsystem do? What is it made of? What eight part essay do you need to remember?
Slam 02. overall framework
Yolov7 training dangerous goods identification pytorch
Kubernetes---- installing and deploying NFS servers
如何面对科技性失业?
Flutter dart generates a list of random numbers that are not repeated in n intervals
【TypeScript】TypeScript常用类型(下篇)
目标检测网络R-CNN 系列
How to optimize a large number of if else [email protected] Detailed explanation of valib
jvm:类加载子系统干什么的?由什么组成?需要记住哪些八股文?
[5gc] what is 5g slice? How does 5g slice work?
Detailed explanation of redis's single login
【TypeScript】TypeScript常用类型(上篇)
基于WebRTC和WebSocket实现的聊天系统
Router. Push(), router. Reply(), router. Go()
Px2rem loader converts PX into REM and adapts to mobile vant UI and other frameworks
Incorrect use of parentdatawidget when the exception was thrown, this was the stack: