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

SQLで今日の予約一覧を取り出す方法

Posted at

こんにちは。

SQLで「今日公開している映画の一覧」や「今日ホテルに泊まりに来ているユーザー一覧」を
表示させます。

カラムのstartからendで範囲を指定。

カラム
start date
end date

今回は「今日ホテルに泊まりに来ているユーザー一覧」を予約としてresevationsテーブルを取り出します。

"SELECT * FROM  users JOIN reservations ON users.id = reservations.user_id WHERE current_date BETWEEN reservations.start AND reservations.end"

usersテーブルを結合しててわかりにくいので大事なところだけ切り取ります。

WHERE current_date BETWEEN reservations.start AND reservations.end

これでstartからendの範囲の値を取り出すことができます:sunny:

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?