我们今天主要向大家爱描述的是SQL Server数据库分组排序后取每组的第 N 行数据的实际操作步骤,首先我们是从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
以上的相关内容就是对SQL Server数据库分组排序后取每组的第N行数据的介绍,望你能有所收获。
【编辑推荐】
文章标题:SQL Server数据库分组排序后的操作
网页链接:http://www.shufengxianlan.com/qtweb/news39/428389.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联