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

T-SQL 確定“失序"記錄

T-SQL to determine quot;out of sequencequot; records(T-SQL 確定“失序記錄)
本文介紹了T-SQL 確定“失序"記錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 SQL 服務器,我需要確定亂序"的記錄;來自一張桌子.

I am using SQL server and I need to determine records that are "out of sequence" from a table.

我會通過一個例子來解釋.我有以下表結構:

I'll explain through an example. I have the following table structure:

OrderNumber OrderStatus EventDateTime
0001522989  22          2014-04-14 05:49:25.4414243
0001522989  26          2014-04-14 05:51:16.7047485
0001522989  23          2014-04-14 05:51:17.8602798
0001522990  23          2014-04-14 05:51:19.9603575
0001522990  24          2014-04-14 05:52:06.5803494
0001522990  24          2014-04-14 05:52:06.5803494

現在我需要生成無序"發送的 OrderNumber 列表.所以在這個例子中,列表將只包含一個值:0001522989".

Now I need to produce a list of OrderNumbers that were sent "out of order". So in this example, the list will contain only one value: "0001522989".

訂單 0001522990 以正確的順序發送(首先是狀態 23,然后是狀態 24,然后是狀態 24(這不算作無序")).

Order 0001522990 was sent in the correct sequence (first status 23, then status 24 and then again status 24 (this doesn't count as "out of sequence")).

訂單 0001522989 的發送順序不正確(先是狀態 22,然后是狀態 26,然后是狀態 23).

Order 0001522989 was not sent in the correct sequence (first status 22, then status 26 and then status 23).

知道如何實現這一點嗎?

Any idea on how I can accomplish this?

我添加了訂單連續兩次發送相同狀態的可能性(這不應算作亂序")

I added the possibility of an order to send out the same status twice in a row (this shouldn't count as "out of sequence")

提前致謝.

推薦答案

從 SQL Server 2008 開始...

In SQL Server 2008 onwards...

SELECT
  OrderNumber
FROM
(
  SELECT
    *,
    ROW_NUMBER() OVER (PARTITION BY OrderNumber ORDER BY OrderStatus, EventDateTime  )   AS sequenceCorrect,
    ROW_NUMBER() OVER (PARTITION BY OrderNumber ORDER BY              EventDateTime)   AS sequenceActual
  FROM
    yourTable
)
  AS yourTableSequenced
WHERE
  sequenceCorrect <> sequenceActual
GROUP BY
  OrderNumber
ORDER BY
  OrderNumber


糟糕,我忘記了 WHERE 子句,現在應該可以工作了 ;)

EDIT : Oops, I forgot the WHERE clause, should work now ;)

這篇關于T-SQL 確定“失序"記錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
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屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日韩成人在线观看 | 91成人精品 | 日韩精品久久久久久 | 亚洲视频在线观看 | 久久久91精品国产一区二区三区 | 欧美性一区二区三区 | 日屁网站 | 一区二区三区国产好 | 亚洲男女视频在线观看 | 日韩成人免费视频 | 国产高清久久久 | 精品久久香蕉国产线看观看亚洲 | 综合视频在线 | 欧美不卡在线 | 紧缚调教一区二区三区视频 | 91一区二区三区在线观看 | 一区二区三区在线观看视频 | 综合另类 | 国产九九av | japan25hdxxxx日本 做a的各种视频 | 另类二区| 国产免费又黄又爽又刺激蜜月al | 91精品国产乱码麻豆白嫩 | 人成在线 | 久久久视频在线 | 一级在线| 天堂色综合 | 超碰精品在线 | 精品国产一区二区三区久久久蜜月 | 91爱啪啪 | 国产精品亚洲成在人线 | 久久久国产精品视频 | 国产精品视频在线免费观看 | 国产精品精品视频一区二区三区 | 激情黄色在线观看 | 亚洲精品一区二区三区中文字幕 | 国产精品日韩在线 | 午夜影院在线观看免费 | 欧美日韩亚洲国产 | 亚洲精品国产成人 | 欧美一级观看 |