-1

I need a column that gives me the difference of a column of a previous row and current row. I am able to achieve this using a select statement. Using

SELECT *,`open` - LAG(`close`,1,`open`) over (order by `open`) as `previous_day_close`  FROM backtestData.NSE_RELIANCE ;

The table looks like this after running the query

Table structure How can I permanently add such a column?

Squirrel
  • 23,507
  • 4
  • 34
  • 32
Ramesh2209
  • 17
  • 4

1 Answers1

1

Create a VIEW.

Window functions can't be used in generated columns, but you can make a VIEW of the query you show.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828