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 2005 Forums
 Transact-SQL (2005)
 Minor issue with Sum()

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2009-12-02 : 09:22:58
Why am I getting an Invalid column name 'vol' when I run the below query?

select c.symbol, sum(bi.volume) as vol
from invoices bi
inner join company c on bi.company_id = c.company_id
group by c.symbol, vol

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-02 : 09:28:02
You just need this

select c.symbol, sum(bi.volume) as vol
from invoices bi
inner join company c on bi.company_id = c.company_id
group by c.symbol

Madhivanan

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

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2009-12-02 : 09:31:11
To elaborate a bit you can not group by the column you are aggregating. I've noticed if you don't answer something within the first 5 seconds of posting Madhiv will beat you to it ;-)
Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2009-12-02 : 09:33:35
Madhivanan is the man!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-02 : 09:35:31
<<
I've noticed if you don't answer something within the first 5 seconds of posting Madhiv will beat you to it ;-)
>>



Madhivanan

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

- Advertisement -