September 11, 2012 at 3:33 am
i want to display a table in Hierarchie.
the thing is that the table dosen't have parent id or somthing like that.
attached is an example for before and after
10X 🙂
September 11, 2012 at 4:20 am
I can't see your example. Can you post it another way?
September 11, 2012 at 6:33 am
September 11, 2012 at 6:55 am
The first thing I advise is taking a look at what you actually want mapped. It doesn't make sense to me.
You want app3 stuff mapped to app4?
The second thing I recommend is giving us the DDL for the table, an INSERT statement with sample data, and then post a typed example (rather than an image) of what you want the results of the query to look like (because that's not the same thing as the excel sheet image you posted).
Then we can help you find your best options.
In the meantime, I can recommend that you look into Row_Number() and Common Table Expressions.
September 11, 2012 at 6:57 am
solved
select CASE WHEN MIN(t.r) = 1 then t.name1
ELSE ''
END as name1,
t.name2, t.name3, sum(t.sum1), sum(t.sum2)
from (select *, ROW_NUMBER() over(partition by name1 order by name1) r
from #tbl1) as t
group by t.name1, t.name2, t.name3
September 11, 2012 at 7:53 am
Glad I could help.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply