回答編集履歴

1

サンプル追記

2016/09/13 04:53

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -11,3 +11,35 @@
11
11
 
12
12
 
13
13
  SQLでやると楽だと思います
14
+
15
+
16
+
17
+ # サンプル
18
+
19
+ ```SQL
20
+
21
+ create table yoyaku(id int not null primary key auto_increment,fdate date , tdate date);
22
+
23
+ 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');
24
+
25
+
26
+
27
+ ```
28
+
29
+
30
+
31
+ 上記に仮に9/2~9/3を挿入する場合以下のようにしてください
32
+
33
+ ```SQL
34
+
35
+ insert into yoyaku (fdate,tdate)
36
+
37
+ select @a,@b from (select @a:='2016-09-02',@b:='2016-09-03') as dummy
38
+
39
+ where 0=(select count(*) from yoyaku where @a<=tdate and @b>=fdate) and @a<=@b;
40
+
41
+ ```
42
+
43
+ あとは@aと@bに代入する値をいろいろ変えてテストしてみてください
44
+
45
+