久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何按 SQL 中的任意條件排序

How to order by an arbitrary condition in SQL(如何按 SQL 中的任意條件排序)
本文介紹了如何按 SQL 中的任意條件排序的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有下表:

CREATE TABLE Bable(id int 身份主鍵,名稱 varchar(20),關(guān)于 varchar(30));INSERT INTO Bable (name,about) VALUES('ООО Name Firm 1','texttexttexttext'),('ООО Name Firm 2','texttexttexttext'),('ООО Name Firm 3','texttexttexttext'),('ООО Name Firm 4','texttexttexttext'),('ООО Name Firm 5','texttexttexttext'),('ООО Name Firm $1','texttexttexttext'),('ООО Name Firm $2','texttexttexttext'),('ООО Name Firm $3','texttexttexttext'),('ООО Name Firm 6','texttexttexttext'),('ООО Name Firm 7','texttexttexttext')

我可以編寫如下查詢:

SELECT * FROM Bable WHERE about = 'texttexttexttext'

如何更改此查詢以返回排序的結(jié)果,使得名稱包含$"的那些首先出現(xiàn),然后是那些不出現(xiàn)的,然后每個(gè)組按 name 升序排列?

表格結(jié)構(gòu)在這里

解決方案

SELECT *從 BableORDER BY CASE WHEN name LIKE '%$..' THEN 0 ELSE 1 END,姓名

  • SQLFiddle 演示

I have the following table:

CREATE TABLE Bable
    (
     id int identity primary key, 
     name varchar(20), 
     about varchar(30)
    );
INSERT INTO Bable (name,about) VALUES
('ООО Name Firm 1','texttexttexttext'),
('ООО Name Firm 2','texttexttexttext'),
('ООО Name Firm 3','texttexttexttext'),
('ООО Name Firm 4','texttexttexttext'),
('ООО Name Firm 5','texttexttexttext'),
('ООО Name Firm $1','texttexttexttext'),
('ООО Name Firm $2','texttexttexttext'),
('ООО Name Firm $3','texttexttexttext'),
('ООО Name Firm 6','texttexttexttext'),
('ООО Name Firm 7','texttexttexttext')

And I can write a query like the following:

SELECT * FROM Bable WHERE about = 'texttexttexttext'

How can I alter this query to return results ordered such that those with names containing "$" appear first, followed by those that do not, with each group then ordered by name ascending?

Structure of the table is here

解決方案

SELECT *
FROM   Bable
ORDER  BY CASE WHEN name LIKE '%$..' THEN 0 ELSE 1 END,
          Name 

  • SQLFiddle Demo

這篇關(guān)于如何按 SQL 中的任意條件排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国内精品久久久久久久 | 狠狠色综合网站久久久久久久 | 三级国产三级在线 | 亚洲小视频 | 一区二区三区四区在线 | аⅴ资源新版在线天堂 | 成人在线一区二区 | 区一区二区三在线观看 | 亚洲影音先锋 | 免费一级大片 | 91毛片在线看 | 国产精品黄色 | 久久久国产一区二区三区四区小说 | 蜜桃臀av一区二区三区 | 亚洲精品国产成人 | 成人av在线播放 | 欧美一区二区三区在线观看 | 一区视频在线播放 | 成人三级网址 | 99精品久久99久久久久 | 夜夜骑首页 | 在线色网站 | 精品1区 | 欧美性久久| 日韩成人在线视频 | 一区免费| 国内自拍第一页 | 国产高清性xxxxxxxx | 日韩福利| 久久合久久 | 热久久久久 | 性色av一区 | 亚洲午夜视频 | 一级片子 | 偷拍自拍第一页 | aa级毛片毛片免费观看久 | 亚洲国产一区二区三区 | av大片| 日本激情视频在线播放 | 日韩精品一区二区三区中文字幕 | 国产一区二区三区欧美 |