1
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 3 years have passed since last update.

redashで日付をフォーマットするsql

Last updated at Posted at 2020-06-23

redashを使用しているとき、「何分何秒」でSELECTされるのを「日付」でSELECTするときのフォーマットです

sqlで日付フォーマット

DATE_FORMAT(rec.created_at,'%Y-%m-%d') as created_date

*小文字のyだと2020ではなく、20とだけ出力されるので注意

redashに反映するときは,
[Execute Selected]を押した後で、X軸Y軸にasの後ろ(created_date)をプルダウンから選択する

使い方はこんな感じ
(sales(sl)テーブルから2020年2月4日〜2020年3月4日までの総売上(total)をグラフ化)

SELECT sl.total, DATE_FORMAT(sl.created_at,'%Y-%m-%d') as created_date, usr.age_type
FROM pos.sales as sl
JOIN pos.users as usr
ON usr.id = rec.customer_id
WHERE sl.shop_id = 1 
AND sl.created_at BETWEEN '2020-02-04' AND '2020-03-04'
1
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
1
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?