如何按此顺序显示数据

编程入门 行业动态 更新时间:2024-10-26 20:24:15
本文介绍了如何按此顺序显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,我有这样的桌子 country |国家|人口(百万美元) 印度| Ap | 5 印度| Mp | 6 我们| mUscha | 10 美国| NewYoek | 6 我们| mUscha | 10 我想放出里拉 country |国家|人口(百万美元) 印度| Ap | 5 | Mp | 6 11 我们| mUscha | 10 | NewYoek | 6 | mUscha | 10 26 国家仅在第一行显示,人口总数显示特定国家/地区结束组行 你可以引导或发送任何片段

Hello, I have table like this country | State | population(in Millions) India | Ap | 5 India | Mp | 6 Us | mUscha| 10 US | NewYoek| 6 Us | mUscha| 10 i want out put lile country | State | population(in Millions) India | Ap | 5 | Mp | 6 11 Us | mUscha| 10 | NewYoek| 6 | mUscha| 10 26 country display only in first row and total of population display particlular country end group next row can u guide or send any snippets

推荐答案

嗨Suhelsa, 好问题 我已经完成了3个步骤 1)将数据提取到临时表#temp Hi Suhelsa, Nice Question I have done this in 3 Steps 1) Extract Data into Temporary table #temp /* assuming Your Table Name as - TblCountry */ Select * into #temp from TblCountry

2)在临时表中插入总人口数行

2) Insert Total Population Rows in Temporary Table

insert into #temp select country,''state, SUM(Population)Population from #temp group by country

3)根据国家和州的顺序设置排名

3) Set Rank Number on the basis of contry and Order by State

select Rank() over (Partition By #temp.Country order by #temp.Country , state desc) row , * into #tempOutput from #temp

4)更新#tempOutput set Country名称=''''其中Row> 1

4) Update #tempOutput set Country Name ='''' where Row > 1

update #tempOutput set Country ='' where ROW > 1

5)从输出表中选择并删除临时表创建的

5) Select from Output Table and drop Temporary table Created

Select * from #tempOutput drop #tempOutput drop #temp

请投票支持我的解决方案 谢谢! Yogendra Dubey

Please vote for My Solution Thanks ! Yogendra Dubey

更多推荐

如何按此顺序显示数据

本文发布于:2023-07-16 20:10:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按此   顺序   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!