I couldn't find an answer to this specific to BigQuery. Basically I want to be able to count ROW_NUMBER in a query and then modify the row number with basic math operators (add, subtract, etc) without using a subquery.
I know the following code works, but to me it seems unnecessary to use a subquery just to append basic math operators
SELECT
id,
title,
language,
rn+5
FROM
(
SELECT
id,
title,
language,
ROW_NUMBER() OVER() AS rn
FROM [publicdata:samples.wikipedia] LIMIT 1000
)
However when I try to add the plus sign without the subquery I get an error
SELECT
id,
title,
language,
ROW_NUMBER() OVER() +5 AS rn_offset,
FROM [publicdata:samples.wikipedia] LIMIT 1000
Is what I'm trying to do possible in BigQuery without a subquery, or is my syntax in error?
Thanks, Onji
,
before theFROM
clause,
beforeFROM
clause is not a problem at all!using subquery just to append with basic match operator
can seem as unnecessary - BUT at the same time I see no practical use of your example at all! What would be reason for you to increaseROW_NUMBER()
inline with row_number() itself. if there is some further use of it - it should be reflected there which most likely anyway will involve subquery. Anyway - can you give your exactpractical
use case?