久久久久久久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的网站 | 精品成人免费视频 | 亚洲高清视频一区二区 | 午夜在线免费观看视频 | 久久在线视频 | 97精品久久| 欧美一级毛片免费观看 | 欧美精品久久久久久久久久 | 久久91| 亚洲精品4 | 亚洲免费一区二区 | 欧美激情精品久久久久 | 成人精品一区二区三区中文字幕 | www日本在线观看 | 中文字幕在线一区 | 夜夜爽99久久国产综合精品女不卡 | 精品九九久久 | 亚洲第一区国产精品 | 国产精品久久久久久久久久久久久久 | 国产精品久久久久久一区二区三区 | 日本精品网站 | 免费在线一区二区 | 欧美一区二区 | 中文字幕一区在线观看视频 | 色婷婷av777 av免费网站在线 | 亚洲精选久久 | 国产欧美日韩视频 | 欧美电影一区 | 国产一区二区精品在线观看 | 国产一区不卡在线观看 | 在线免费观看黄a | 亚洲一区中文字幕 | 91精品国产乱码久久久久久久久 | 久久综合久色欧美综合狠狠 | 三级成人在线 | 成人av片在线观看 | 免费在线观看一级毛片 |