BigQueryでORDER BY句を使用する場合、デフォルトのNULLの順序はASCかDESCで異なる。ASCの場合はNULLが最初に来るし、DESCの場合はNULLが最後に来る。
- NULLS FIRST is applied by default if the sort order is ascending.
- NULLS LAST is applied by default if the sort order is descending.
デフォルトのNULLの順序で困る場合は、ORDER BY句で、NULLS FIRST
、NULLS LAST
を使用することでNULLのソート順を制御できる。
参考
https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#order_by_clause