Column 'discount' can not be resolved. How to use a column that is the result of a calculation to calculate another column in the same query?

2

I have the following query:

Select price, col2, col3*7.5 AS desconto, (price*desconto) AS finalprice
From tab1.

When I run I get the following message: Column 'desconto' cannot be resolved .

How do I resolve this error?

Note: I'm running AWS Athena that follows the same SQL standard .

    
asked by anonymous 15.10.2018 / 19:29

2 answers

2

Based on your Query, is not it better to do it as below?

Select price, col2, col3*7.5 AS desconto, (price*(col3*7.5)) AS finalprice
From tab1.
    
15.10.2018 / 21:38
1

One option is to use subquery in FROM :

SELECT x.*,
       x.price * x.desconto AS finalprice
  FROM (
    SELECT price,
           col2,
           col3 * 7.5 AS desconto
      FROM tab1
  ) x
    
15.10.2018 / 21:42