「SQL」betweenで日時型の列目を範囲で指定するサンプル

書式
SELECT * FROM テーブル名
WHERE 項目名  BETWEEN 日時1 AND 日時2
使用例1

SELECT
  * 
FROM
  NEWS_TBL 
WHERE
  FROM_DT BETWEEN '2021/07/03' AND '2021/08/07' 
ORDER BY
  UID;

使用例2

SELECT
  * 
FROM
  NEWS_TBL 
WHERE
  FROM_DT BETWEEN '2021/07/03 11:11:11' AND '2021/08/07 23:59:38' 
ORDER BY
  UID;

 

SQL

Posted by arkgame