问题描述
你好,我有这样的桌子
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
推荐答案
/*
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
这篇关于如何按此顺序显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!