新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQL Server數(shù)據(jù)庫分組排序后的操作
我們今天主要向大家愛描述的是SQL Server數(shù)據(jù)庫分組排序后取每組的第 N 行數(shù)據(jù)的實際操作步驟,首先我們是從select代碼示例開始的,假如你對其實際操作有興趣了解的話,你就可以通過以下的文章對其進行了解。

示例代碼select
- A.[DocNo] as [docno],
- A1.[Item_ItemCode] as [itemcode],
- A2.[LineNum] as [linenum],
- A2.[ARBillLine] as [arbillLine],
- A2.[Maturity] as [maturity],
- A2.[AROCMoney_TotalMoney] as [totalmoney
示例代碼select
- A.[DocNo] as [docno],
- A1.[Item_ItemCode] as [itemcode],
- A2.[LineNum] as [linenum],
- A2.[ARBillLine] as [arbillLine],
- A2.[Maturity] as [maturity],
- A2.[AROCMoney_TotalMoney] as [totalmoney],
- A2.[AROCMoneyBalance_TotalMoney] as [totalBalanceMoney]
- into #tempShouhuoFenqi
- from AR_ARBillHead as A
- left join [AR_ARBillLine] as A1 on (A.[ID] = A1.[ARBillHead])
- left join [AR_ARInstalment] as A2 on (A1.[ID] = A2.[ARBillLine])
- group by A.DocNo,A1.Item_ItemCode,A2.LineNum,A2.ARBillLine,A2.Maturity,A2.AROCMoney_TotalMoney,A2.AROCMoneyBalance_TotalMoney
- -- select * from #tempShouhuoFenqi
- -- drop table #tempShouhuoFenqi
合同起始日期:第期的日期
- select docno,arbillline,maturity1
- into #tempMaturity1 from
- (
- select docno,arbillline
- ,maturity as maturity1,
- row_number() over
- (partition by docno,arbillline --按docno,arbillline分組
- order by maturity asc) as rowno --按maturity排序
- from #tempShouhuoFenqi ) x
- where x.rowno=2 --取分組排序后的第行
- ---- select * from #tempMaturity1
- ---- drop table #tempMaturity1
以上的相關(guān)內(nèi)容就是對SQL Server數(shù)據(jù)庫分組排序后取每組的第N行數(shù)據(jù)的介紹,望你能有所收獲。
【編輯推薦】
- MS SQL Server 連接字符串的實際操作簡介
- SQL Server數(shù)據(jù)庫中字符串操作要用到的函數(shù)有哪些?
- SQL Server 連接字符串的一些聲明
- SQL Server 連接字符串的實現(xiàn)步驟
- SQL Server數(shù)據(jù)庫中可用格式字符串干什么?
分享名稱:SQL Server數(shù)據(jù)庫分組排序后的操作
當前地址:http://fisionsoft.com.cn/article/cdecsse.html


咨詢
建站咨詢
