Problem with doing a group by | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Problem with doing a group by

I have run into a very simple query. Since I rarely do SQL programming, I am asking this query. I have results returned from two queries. I need to get the aggregate of the second column. Sample query is as follows :create table emp1(name varchar(100), age int)create table emp2(name varchar(100), age int)insert into emp1values(‘Jacob’,25)insert into emp1values(‘Jacob’,75)I want the result to be :Name : Jacob Age : 100Please help.
Not really an aggregate query, except if there are multiple matches on the name.
So if there’s just one matching row between the two tables, all you need is a JOIN on the name column, and an expression that adds up the two columns.
If there are multiple matches, and you need to add them all up, add SUM() around each column that you’re adding up, and GROUP BY on the name column.

The process is simple. First Join these two tables and then sum Age of two employees. SELECT
e1.NAME,SUM(e1.Age+ e2.Age)FROM #emp1 e1 JOIN #emp2 e2 ON e2.[NAME]=e1.[NAME] GROUPBY e1.
[NAME]
I have run into a very simple query. Since I rarely do SQL programming, I am asking this query. I have results returned from two queries. I need to get the aggregate of the second column. Sample query is as follows :create table emp1(name varchar(100), age int)create table emp2(name varchar(100), age int)insert into emp1values(‘Jacob’,25)insert into emp1values(‘Jacob’,75)I want the result to be :Name : Jacob Age : 100Please help.
Welcome to the forums.!
Tanveer, always check the post date. This one is 4 years old.
Anyway thank for your collaboration.:)
when i answer then i saw the reported date.
so anyway will tell me the problem doing with group by ?:confused:
Welcome to the forums.!
Tanveer, always check the post date. This one is 4 years old.
Anyway thank for your collaboration.:)
]]>

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |