· 8 years ago · Mar 10, 2018, 09:34 AM
1select
2 (case
3 when b2.xleft >= b1.xright
4 or b2.ytop >= b1.ybottom
5 or b1.xleft >= b2.xright
6 or b1.ytop >= b2.ybottom
7 then 'false'
8 else 'true' end) as overlap
9from
10 (select 0 xleft, 0 ytop, 100 xright, 100 ybottom) b1
11, (select 100 xleft, 0 ytop, 200 xright, 100 ybottom) b2;
12
13-- 個人的ã«ã¯CREATE TABLEã™ã‚‹æ–¹ãŒå¥½ã¿
14drop table if exists box;
15create table box(
16 id int auto_increment primary key
17 , xleft int not null
18 , ytop int not null
19 , xright int not null
20 , ybottom int not null
21);
22
23insert into
24 box(xleft, ytop, xright, ybottom)
25values
26 (0, 0, 100, 100)
27, (100, 0, 200, 100)
28, (0, 50, 100, 150)
29, (0, 100, 100, 200)
30, (100, 100, 400, 400)
31, (200, 200, 500, 500);
32
33select
34 (case
35 when b2.xleft >= b1.xright
36 or b2.ytop >= b1.ybottom
37 or b1.xleft >= b2.xright
38 or b1.ytop >= b2.ybottom
39 then 'false'
40 else 'true' end) as overlap
41from
42 (select * from box where id = 1) b1
43, (select * from box where id = 2) b2;