Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 help with select statement

Author  Topic 

clean
Starting Member

7 Posts

Posted - 2006-05-04 : 13:05:00
table A has locations that relate to table B

aID city
1 toronto
2 london

table B has the following

bid aID ordernum amount
1 1 555 5000
2 1 345 7000
3 1 236 3000
4 2 638 7050
5 2 434 5755

and so on
what i need my select statement to do if it's even possible is
total the amounts grouped by aID and display the city from table A and the total from table B

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-05-04 : 13:10:26
Pretty basic stuff.
JOIN the 2 tables by aID, GROUP BY aID, SELECT aID along with the aggregate function COUNT.

All key words are detailed with examples in the help that comes with Sql Server: Books Online.

Be One with the Optimizer
TG
Go to Top of Page

druer
Constraint Violating Yak Guru

314 Posts

Posted - 2006-05-04 : 13:18:29
Select a.aID, SUM(b.amount) as AmountTotal
from TableA a inner join TableB b on b.aID = a.ID
group by a.aID

Hope it helps,
Dalton

Blessings aren't so much a matter of "if they come" but "are you noticing them."
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-05 : 04:37:26
Also Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -