Forum Discussion
Greg_Deckler
5 years agoCommunity Champion
How to Get Your Question Answered Quickly
Ever wonder why some questions get answered so quickly while others languish or are seemingly completely ignored? Fear not, this article will help guide you into getting your question answered quickl...
Rakesk13
3 months agoHelper III
Hi team,
i have two different table with two different age bucket like
Table 1:
Age ID
0-5 10
5-10 20
60-90 5
Table 2:
Age ID
0-5 30
5-10 60
11-20 70
OUTPUT:
Age ID
0-5 40
5-10 80
11-20 70
60-90 5
looking for this type of output,please can you help on this, really appreciated for quick help.
Thanks & Regards,
Rakesh Jadhav
Tummalapati_95
3 months agoFrequent Visitor
Hi Rakesh,
You can achieve this output by a UNION ALL followed by a GROUP BY on the age bucket.
SELECT
Age,
SUM(ID) AS ID
FROM (
SELECT Age, ID FROM Table1
UNION ALL
SELECT Age, ID FROM Table2
) AS Combined
GROUP BY Age
ORDER BY CAST(LEFT(Age, CHARINDEX('-', Age) - 1) AS INT);
Let me know how it went?
Thanks,
Praveen
- FayazAhmad2 months agoFrequent Visitor
- The data days is pretty awesome for me because I learned a lot of things from here ♥️