Answer by Shawn.X for Grouping over the subquery in SQL on unique id
select x.sum_a, x.sum_b, x.sum_c, x.sum_d, t.id1from tmpTable tjoin(select id1, sum(A) as sum_a, sum(B) as sum_b, sum(C) as sum_c, sum(D) as sum_dfrom tmpTablegroup by id1) x on t.id1 = x.id1
View ArticleAnswer by Shawn for Grouping over the subquery in SQL on unique id
If your current real query is summing up a and b the way you want and generating that first sample output, maybe something like:SELECT DISTINCT SUM(a), SUM(b), SUM(c) OVER (PARTITION BY id1), SUM(d)...
View ArticleAnswer by Navik Hiralal for Grouping over the subquery in SQL on unique id
Seeing as you have different grouping criteria for A and B, you can group them separately to C and D. The below (using common table expression) might start you on the right track: ; with SummaryValues...
View ArticleGrouping over the subquery in SQL on unique id
I've a query which gets results from temp table. It has aggregate columns which are derived from the temp table:SELECT DISTINCT SUM(a), SUM(b), c, d, id1FROM #tmpTable . . . join with many other...
View Article
More Pages to Explore .....