Skip to content
Advertisement

How to subtract from certain cell in Bigquery?

I have data date and a in this table my table How I can get b where the value is a subtract by a from previous date?

Advertisement

Answer

You may use the LAG analytic function here:

SELECT date, a, a - LAG(a) OVER (ORDER BY date) AS b
FROM yourTable
ORDER BY date;
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement