![見出し画像](https://assets.st-note.com/production/uploads/images/84916837/rectangle_large_type_2_ef92d4789e8ec2083f142fd7f7fde886.png?width=1200)
Photo by
nai3_5raku
BigQueryで誕生日から年齢を計算する方法
DATE_DIFFを使う方法
今日の日付から年齢を計算
SELECT
DATE_DIFF(CURRENT_DATE(), birthday, YEAR) AS age
FROM customers
特定の日付から年齢を計算
SELECT
DATE_DIFF(DATE "2019-12-31", birthday, YEAR) AS age
FROM customers
CASTとFORMAT_DATEとFLOORを使う方法
SELECT
CAST((CAST(FORMAT_DATE('%Y%m%d', CURRENT_DATE()) AS INT64) - CAST(FORMAT_DATE('%Y%m%d', birthday ) AS INT64)) / 10000 AS int64) AS current_age
FROM customers