Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to do this in View.
Message
 
 
To
10/07/2003 05:06:22
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00808770
Message ID:
00808808
Views:
22
Hi Noel,

You can use UNION and derived table to do that
SELECT ab.name, SUM(ab.totalservice)
FROM (
	SELECT name, SUM(totalservice) AS totalservice 
		FROM tablea GROUP BY name 
	UNION
	SELECT name, SUM(totalservice) AS totalservice 
		FROM tableb GROUP BY name 
	) ab
GROUP BY ab.name ORDER BY ab.name
>Hi to all,
>
>I have here two tables,
>
>
>   Table A                    Table B
>
>   TOTALSERVICE   NAME        TOTALSALES   NAME
>     500          A              100       A
>     600          B              300       B
>     700          C              400       D
>
>
>
>and wanted to produce the following output
>
>
>   TOTALSALESSERVICE    NAME
>        600             A
>        900             B
>        700             C
>        400             D
>
>
>Great ideas are very much welcome.
>
>Looking forward for an answer.
>
>Noel
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform