teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

サンプル追記

2016/09/13 04:53

投稿

yambejp
yambejp

スコア117944

answer CHANGED
@@ -4,4 +4,19 @@
4
4
  - B<C
5
5
  - D<A
6
6
 
7
- SQLでやると楽だと思います
7
+ SQLでやると楽だと思います
8
+
9
+ # サンプル
10
+ ```SQL
11
+ create table yoyaku(id int not null primary key auto_increment,fdate date , tdate date);
12
+ insert into yoyaku (fdate,tdate) values('2016-09-01','2016-09-01'),('2016-09-05','2016-09-07'),('2016-09-10','2016-09-11'),('2016-09-20','2016-09-25');
13
+
14
+ ```
15
+
16
+ 上記に仮に9/2~9/3を挿入する場合以下のようにしてください
17
+ ```SQL
18
+ insert into yoyaku (fdate,tdate)
19
+ select @a,@b from (select @a:='2016-09-02',@b:='2016-09-03') as dummy
20
+ where 0=(select count(*) from yoyaku where @a<=tdate and @b>=fdate) and @a<=@b;
21
+ ```
22
+ あとは@aと@bに代入する値をいろいろ変えてテストしてみてください