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
 calculation within SELECT query

Author  Topic 

phobos300
Starting Member

3 Posts

Posted - 2011-06-08 : 09:51:41
Hi all,

I have a question regarding select query:
Is it possible to e.g sum keys XX and YY ?
I need to sum those 2 values without using the something/something_else again.

The query below is giving error:
[Error Code: 1054, SQL State: 42S22] Unknown column 'something' in 'field list'

select
something as XX,
something_else as YY,
XX+YY as ZZ
from sometable


thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-08 : 09:58:19
[code]
select XX, YY, XX+YY as ZZ
from
(
select something as XX,
something_else as YY
from sometable
) t
[/code]


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

Go to Top of Page

phobos300
Starting Member

3 Posts

Posted - 2011-06-08 : 10:34:44
Thanks khtan
but your advise doesn't work
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-08 : 10:51:05
why ?


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

Go to Top of Page

phobos300
Starting Member

3 Posts

Posted - 2011-06-08 : 10:55:41
Its giving me an error:
[Error Code: 1248, SQL State: 42000] Every derived table must have its own alias
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-08 : 10:58:05
SQLTeam.com is on Microsoft SQL Server. For MySQL, please post at dbfourms.com or forums.mysql.com


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

Go to Top of Page
   

- Advertisement -