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
 Plz Help......

Author  Topic 

wormz666
Posting Yak Master

110 Posts

Posted - 2008-09-18 : 02:22:19
i have a problem with the query
i want to view how much i earned for each product

table1
prodid numeric
desc varchar
uprice int
table2
tranid numeric
prodid numeric
qty int

Select table1.prodid,(sum(table2.qty) * uprice) from table1
inner join table2 on table1.prodid=table2.prodid
where table1.prodid=table2.prodid








khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-18 : 02:25:42
you missed the GROUP BY prodid


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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 02:27:28
quote:
Originally posted by khtan

you missed the GROUP BY prodid


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




Also group by uprice
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-18 : 02:31:52
why group by uprice ?

I guess the wrong placement of parenthesis confuses you


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

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-18 : 02:33:51
oh the parenthesis is wrong also


Select table1.prodid, sum(table2.qty * uprice)
from table1
inner join table2 on table1.prodid = table2.prodid
where table1.prodid=table2.prodid -- this is redundant
group by table1.prodid



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

Go to Top of Page

wormz666
Posting Yak Master

110 Posts

Posted - 2008-09-18 : 02:44:10
thank you very much i am new member of this forum...
and i guess i will learned much more on this site....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 03:38:39
quote:
Originally posted by khtan

oh the parenthesis is wrong also


Select table1.prodid, sum(table2.qty * uprice)
from table1
inner join table2 on table1.prodid = table2.prodid
where table1.prodid=table2.prodid -- this is redundant
group by table1.prodid

yup got confused
thanks for clarification

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



Go to Top of Page
   

- Advertisement -