0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Bigqueryにおける日付操作(備忘録)

Last updated at Posted at 2023-08-25

EXTRACT関数を用いることにより、スキーマがDATEの場合に簡単に操作をすることが可能

今回の場合は、customerテーブルで年ごとのcustomerの数を数えています。
DAYやMONTHも可能

SELECT 
  EXTRACT(YEAR FROM birth_day) AS birth_year, 
  EXTRACT(MONTH FROM birth_day) AS birth_month,
  -- EXTRACT(DAY FROM birth_day) AS birth_day,
  COUNT(*) AS count,
FROM `100_knock.customer`
GROUP BY birth_year,birth_month
ORDER BY birth_year

実行結果
スクリーンショット 2023-08-25 11.28.23.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?