2
votes

Is there any equivalent 'Qualify' clause of Teradata in BigQuery Standard SQ?

I need it because we cant use analytic functions in Where/Having clause.

2
What about pushing your analytic function down to a sub/nested select and filtering on top of it? - Graham Polley
I don't believe it exists. I could be wrong, but I don't see anything in the docs. - Graham Polley
you can submit feature request for this! - Mikhail Berlyant
QUALIFY appears to be a Teradata-specific extension to the SQL standard that isn't implemented by any other SQL engines. - Elliott Brossard
@ElliottBrossard Good to know that Snowflake supports it too :) - Why no windowed functions in where clauses? - Lukasz Szozda

2 Answers

2
votes

The equivalent query is:

SELECT * EXCEPT (_row_number)
FROM  (SELECT {{ COLUMNS }}
              , ROW_NUMBER() {{ RULE }} AS _row_number
       FROM   {{ MY_TABLE }}) AS t
WHERE  _row_number = 1