当前位置:网站首页>SQL custom collation
SQL custom collation
2022-07-03 18:37:00 【"@ book mountain has a path%"】
SQL Custom collation
The original data

Result sequence data display
Apply: Submit a request
Review: Wait for a response
Finish: Task to complete
Sort by date and status , First status is : Submit a request (Apply)— In reverse chronological order , Then the status is : Wait for a response (Review)— In reverse chronological order , Then the status is : Task to complete (Finish)— In reverse chronological order .
Create table statement
DROP TABLE IF EXISTS `customsort`;
CREATE TABLE `customsort` ( `status` VARCHAR ( 255 ), `date1` date );
INSERT INTO `customsort` VALUES ('Review', '2022-01-11');
INSERT INTO `customsort` VALUES ('Apply', '2022-01-11');
INSERT INTO `customsort` VALUES ('Review', '2022-01-01');
INSERT INTO `customsort` VALUES ('Finish', '2022-01-14');
INSERT INTO `customsort` VALUES ('Apply', '2022-01-01');
INSERT INTO `customsort` VALUES ('Review', '2022-01-05');
Use case when Conditions then result ........ end
SELECT STATUS
,
date1,
( CASE WHEN STATUS = 'Apply' THEN 0 WHEN STATUS = 'Review' THEN 1 WHEN STATUS = 'Finish' THEN 2 ELSE 3 END ) type
FROM
customsort
to status Assign values with sort size type
Custom sort SQL
SELECT STATUS
,
date1
FROM
customsort
WHERE
STATUS IN ( 'Apply', 'Review', 'Finish' )
ORDER BY
( CASE WHEN STATUS = 'Apply' THEN 0 WHEN STATUS = 'Review' THEN 1 WHEN STATUS = 'Finish' THEN 3 ELSE 4 END ),
date1 DESC;

There are deficiencies , Please mention it in the comments !!!!!!!
边栏推荐
- Multifunctional web file manager filestash
- English grammar_ Adjective / adverb Level 3 - multiple expression
- Raft log replication
- 199. Right view of binary tree - breadth search
- Sensor debugging process
- Use of unsafe class
- 2022-2028 global scar care product industry research and trend analysis report
- Mysql45 lecture learning notes (II)
- Torch learning notes (2) -- 11 common operation modes of tensor
- Prototype inheritance..
猜你喜欢

Win 11 major updates, new features love love.

Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)

How to track the real-time trend of Bank of London

Computer graduation design PHP campus address book telephone number inquiry system

English grammar_ Adjective / adverb Level 3 - multiple expression

Mysql45 lecture learning notes (II)

Sensor 调试流程

Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download

How to analyze the rising and falling rules of London gold trend chart
![Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]](/img/da/0a282b4773fe3909d1e5e9d19f8549.jpg)
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
随机推荐
What London Silver Trading software supports multiple languages
Summary and Reflection on the third week of winter vacation
圖像24比特深度轉8比特深度
[untitled]
Nodejs (01) - introductory tutorial
Day-27 database
CTO and programmer were both sentenced for losing control of the crawler
Reading a line from ifstream into a string variable
Win 11 major updates, new features love love.
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
SQL injection -day16
How do microservices aggregate API documents? This wave of operation is too good
Unity2018 to wechat games without pictures
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
毕业总结
编程中常见的 Foo 是什么意思?
What is the function of registering DLLs- What does registering a DLL do?
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
虚拟机和开发板互Ping问题
English语法_名词 - 分类