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

帶有 order by 子句的 SQL 查詢

SQL query with order by clause(帶有 order by 子句的 SQL 查詢)
本文介紹了帶有 order by 子句的 SQL 查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個有 3 列的表格.產品、名稱、時間戳.目前,我沒有任何 rownumber 列.如果我從表中獲取記錄,我將使用

I have a table that has 3 columns. Product,Name,TimeStamp. At present, I don't have any rownumber column. If I fetch the record from the table, I will be using

select * 
from table 
order by Product,Name,TimeStamp. 

我會得到一些數據的順序.按照這個順序,我需要另一列應該顯示行號.簡而言之,我需要一個列,該列應該根據上述查詢順序告訴我行號.

I will get some order of data. In that order I need another column that should show the row number. Simply put, I need a column that should tell me the row number based on the above order by query.

是否可以根據某種順序插入值?在創建這樣的表時?

Is it possible to insert values based on some order? while creating table like that?

OPERATOR    PRODUCT USER NAME   TIME STAMP
1           INS1    1YHS        2018-08-15 09:02:33.000
1           INS1    1YHS        2018-08-15 10:46:17.000
2           INS1    1YHS        2018-08-15 11:01:28.000
2           INS1    1YHS        2018-08-15 17:07:47.000

這里如果操作員為 1,則獲取產品 INS1 的許可證,如果操作員為 2,則返回同一產品的許可證.同一個人可以拿更多的執照.第 1 行獲取了許可證的詳細信息,并返回了相同的許可證,該信息存儲在第 3 行中.對于第 2 行,許可證返回信息存儲在第 4 行.

Here if the operator is 1, license for product INS1 is taken and if the operator is 2 then the license for the same product is been returned. Same person can take more licenses. 1st row has the details of license been taken and the same license been returned and that information is stored in the 3rd row. for the 2nd row, the license returned information is stored in the 4th row.

我需要像

OPERATOR    PRODUCT USER NAME   TIME STAMP
1           INS1    1YHS        2018-08-15 09:02:33.000
2           INS1    1YHS        2018-08-15 11:01:28.000
1           INS1    1YHS        2018-08-15 10:46:17.000
2           INS1    1YHS        2018-08-15 17:07:47.000

推薦答案

'Transaction' 是一對 take + return.它的身份是根據源數據計算出來的,因此 OPERATOR 可以按照您需要的方式進行分組.查詢可能會在具有未配對的 OPERATOR s 的數據上失敗.

'Transaction' is a pair of take + return. It's identity is computed from source data so OPERATORs could be grouped the way you need. The query may fail on data with unpaired OPERATORs.

declare @tbl table (
OPERATOR int,   
PRODUCT varchar(50), 
[USER NAME] varchar(100),    
[TIME STAMP] datetime);

insert into @tbl(OPERATOR, PRODUCT, [USER NAME], [TIME STAMP]) values
 (1, 'INS1', '1YHS', '2018-08-15 09:02:33.000')
,(1, 'INS1', '1YHS', '2018-08-15 10:46:17.000')
,(2, 'INS1', '1YHS', '2018-08-15 11:01:28.000')
,(2, 'INS1', '1YHS', '2018-08-15 17:07:47.000');

select OPERATOR, PRODUCT, [USER NAME], [TIME STAMP]
from (
    select OPERATOR, PRODUCT, [USER NAME], [TIME STAMP]
        , row_number() over(partition by PRODUCT, [USER NAME], OPERATOR order by [TIME STAMP]) transId 
    from @tbl) t
order by PRODUCT, [USER NAME], transId, OPERATOR;

這篇關于帶有 order by 子句的 SQL 查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 国产小视频在线 | 国产成人免费视频 | 欧美国产一区二区 | 国产精品久久久久久久久久妇女 | 亚洲成人日韩 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 成人在线视频免费看 | 国产一级成人 | 99精品免费久久久久久久久日本 | 国产精品视频在线播放 | 国产欧美精品一区 | 四色永久 | 国产亚洲精品一区二区三区 | 黄色av网站在线免费观看 | 国产区精品在线观看 | 久久伊人亚洲 | 国产精品视频在线播放 | 精品美女 | 欧美精品一区二区三区四区 | 中文字幕免费视频 | 国产精品日韩在线 | 午夜精品一区 | 欧美a v在线 | 久久久91精品国产一区二区精品 | 亚洲狠狠丁香婷婷综合久久久 | 亚洲欧美日韩一区二区 | 久久精品国产免费一区二区三区 | 午夜在线| 欧美午夜精品理论片a级按摩 | av网站免费 | 中文在线a在线 | 成人免费毛片在线观看 | 欧美日日日日bbbbb视频 | 在线欧美一区二区 | 亚洲福利一区二区 | 亚洲视频 欧美视频 | 精品美女久久久久久免费 | 免费国产一区二区 | 伊人在线视频 | 日韩精品久久一区二区三区 | 日韩欧美精品在线 |