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
 General SQL Server Forums
 New to SQL Server Programming
 joining table

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2007-07-19 : 09:07:15
hi friends can any body help fo rthe below issue:
stock
========
Item cost
pen 150
pencil 150

stockdt
=========
Item qty
pen 10
pen 15
pencil 10
pencil 15

for the above two table of stock,stockdt the o/p should come like this

Item cost qty std.cost

pen 150 25 3750
pencil 150 25 3750

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-19 : 09:26:14
[code]SELECT s.Item, s.cost, d.qty, [std.cost] = s.cost * d.qty
FROM stock s
INNER JOIN
(
SELECT Item, qty = SUM(qty)
FROM stockdt
GROUP BY Item
) d
ON s.Item = d.Item[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -