Derby SQL calculation

I'm having a trouble to do a calculation in Derby.

The problem is the next:

Select column1, (column1 + 10) as newCol, 
(column1+newCol) as newCol2 from sometable;

This throws an error saying that newCol does not exist, in the case (column1+newCol).

Why is not that correct?

Thanks for your help! 😁

Upvotes: 0

Views: 44

Answers (1)

user330315
user330315

Reputation:

You can't access a column alias on the same level where you define it.

You need a derived table:

select column1, newcol, column1 + newcol as newcol2
from (
  Select column1, (column1 + 10) as newCol
  from sometable
) t;

Upvotes: 1

Related Questions