以下の内容はhttps://www.k-hitorigoto.online/entry/2024/02/22/080000より取得しました。


timestamp型の日時から、"時"だけを取り出す

timestamp型の日時から、"時"だけを取り出すSQL(「2023-07-07 13:55:00.000」の場合、「13」を取り出す)

検証環境

 PostgreSQL 14.11 (Debian 14.11-1.pgdg120+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

SQLと実行結果

-- extract(<取得対象> from <取得対象を含む列>)で、<取得対象>を抽出する。今回は「時」
select
	record_date -- timestamp型で日時を格納した列
	,extract(hour from record_date) as time -- 「時」を抽出した列
from
	record_data
record_date time
2023-07-07 11:00:00.000 11
2023-07-07 13:55:00.000 13
2023-07-07 13:55:00.000 13
2023-07-07 13:55:00.000 13
2023-07-07 14:00:00.000 14
2023-07-07 14:20:00.000 14
2023-07-07 17:30:00.000 17
2023-07-07 17:30:00.000 17
2023-07-07 17:35:00.000 17
2023-07-07 17:35:00.000 17
2023-07-07 17:40:00.000 17
2023-07-07 18:10:00.000 18
2023-07-07 19:50:00.000 19
2023-07-07 19:55:00.000 19
2023-07-07 19:55:00.000 19
2023-07-07 20:00:00.000 20

参考にしたページ




以上の内容はhttps://www.k-hitorigoto.online/entry/2024/02/22/080000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14