0
select 
    nodw as "node ID",
    riskvale as "TotalRis",
    (portvalue - marvalue) as "TotalMarValue" 
    --{ Here I want to take the upper column value i.e ""TotalRis"" / "TotalMarValue" * 100 } as "total Uses"**
from 
    abc

I want to use the output of "TotalRis" and "TotalMarValue" column to get the output for other column. I tried with @{TotalRis} but query not getting execute.

omi
  • 11
  • 1
  • what do you mean by `upper column value `? please provide sample data / desired output – eshirvana Sep 07 '22 at 18:44
  • I mean that I want to use the output from "TotalRis" and "TotalMarValue" columns to get the output for other column. So "TotalRis"" / "TotalMarValue" * 100 as "Total Uses" – omi Sep 07 '22 at 18:56
  • then use them. what's the problem – eshirvana Sep 07 '22 at 18:57
  • I tried like this but getting error message "select nodw as "node ID", riskvale as "TotalRis", (portvalue - marvalue) as "TotalMarValue" ( "TotalRis" / "TotalMarValue" ) * 100 as "Total Uses" from abc" SQL Error [42703]: ERROR: column "TotalRis" does not exist Position: 150 – omi Sep 07 '22 at 19:00

1 Answers1

0

you can't use alias , as they are the last part of the query that query engine will parse, so :

select 
    nodw as "node ID",
    riskvale as "TotalRis",
    (portvalue - marvalue) as "TotalMarValue", 
    riskvale / (portvalue - marvalue) * 100  as "total Uses"
from abc
eshirvana
  • 23,227
  • 3
  • 22
  • 38