你好,我有这样的桌子 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 country3)根据国家和州的顺序设置排名
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 #temp4)更新#tempOutput set Country名称=''''其中Row> 1
4) Update #tempOutput set Country Name ='''' where Row > 1
update #tempOutput set Country ='' where ROW > 15)从输出表中选择并删除临时表创建的
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
更多推荐
如何按此顺序显示数据
发布评论