回答編集履歴
2
chousei
test
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
```SQL
|
12
|
+
|
13
|
+
|
12
14
|
|
13
15
|
create table tbl (id int primary key ,
|
14
16
|
|
@@ -48,7 +50,7 @@
|
|
48
50
|
|
49
51
|
SELECT * FROM tbl
|
50
52
|
|
51
|
-
WHERE
|
53
|
+
WHERE reality in('N','R');
|
52
54
|
|
53
55
|
|
54
56
|
|
@@ -56,7 +58,7 @@
|
|
56
58
|
|
57
59
|
SELECT * FROM tbl
|
58
60
|
|
59
|
-
WHERE
|
61
|
+
WHERE reality in('N','R') and `character` ='キャラ1';
|
60
62
|
|
61
63
|
|
62
64
|
|
@@ -64,7 +66,7 @@
|
|
64
66
|
|
65
67
|
SELECT * FROM tbl
|
66
68
|
|
67
|
-
WHERE
|
69
|
+
WHERE JSON_CONTAINS(attribe,'1');
|
68
70
|
|
69
71
|
|
70
72
|
|
@@ -72,4 +74,22 @@
|
|
72
74
|
|
73
75
|
SELECT * FROM tbl
|
74
76
|
|
77
|
+
WHERE JSON_CONTAINS(attribe,'1') and JSON_CONTAINS(attribe,'17');
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
-- (5)
|
82
|
+
|
83
|
+
SELECT * FROM tbl
|
84
|
+
|
85
|
+
WHERE reality='N' and JSON_CONTAINS(attribe,'1');
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
-- (6)
|
90
|
+
|
91
|
+
SELECT * FROM tbl
|
92
|
+
|
75
|
-
WHERE reality='R' and JSON_CONTAINS(attribe,'1')
|
93
|
+
WHERE reality='R' and JSON_CONTAINS(attribe,'1');
|
94
|
+
|
95
|
+
```
|
1
chousei
test
CHANGED
@@ -1,3 +1,75 @@
|
|
1
1
|
やり方的にはsetやenumが楽ですが、あとから変更するのが面倒です
|
2
2
|
|
3
3
|
正規化して属性を管理するか、属性をjson型にするかで対応するとよいでしょう
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# sample
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```SQL
|
12
|
+
|
13
|
+
create table tbl (id int primary key ,
|
14
|
+
|
15
|
+
no varchar(10),
|
16
|
+
|
17
|
+
reality varchar(10),
|
18
|
+
|
19
|
+
`character` varchar(10),
|
20
|
+
|
21
|
+
attribe json
|
22
|
+
|
23
|
+
);
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
insert into tbl values
|
28
|
+
|
29
|
+
(1,'0001','N','キャラ1','[4,17,39,62,82]'),
|
30
|
+
|
31
|
+
(2,'0002','R','キャラ1','[22,26,36,43,45,73,84]'),
|
32
|
+
|
33
|
+
(3,'0003','SR','キャラ1','[6,24,37,44,47,53,58]'),
|
34
|
+
|
35
|
+
(4,'0004','SSR','キャラ1','[2,32,42,47,49,79,84,90]'),
|
36
|
+
|
37
|
+
(5,'0005','N','キャラ2','[1,17,38,59,69,76]'),
|
38
|
+
|
39
|
+
(6,'0006','R','キャラ2','[18,24,35,49,56,74]'),
|
40
|
+
|
41
|
+
(7,'0007','SR','キャラ2','[14,50,51,53,57,63,90]'),
|
42
|
+
|
43
|
+
(8,'0008','SSR','キャラ2','[1,7,19,66,69,70,75,90]');
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
-- (1)
|
48
|
+
|
49
|
+
SELECT * FROM tbl
|
50
|
+
|
51
|
+
WHERE JSON_CONTAINS(attribe,'1')
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
-- (2)
|
56
|
+
|
57
|
+
SELECT * FROM tbl
|
58
|
+
|
59
|
+
WHERE JSON_CONTAINS(attribe,'1') and JSON_CONTAINS(attribe,'17')
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
-- (3)
|
64
|
+
|
65
|
+
SELECT * FROM tbl
|
66
|
+
|
67
|
+
WHERE reality='N' and JSON_CONTAINS(attribe,'1')
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
-- (4)
|
72
|
+
|
73
|
+
SELECT * FROM tbl
|
74
|
+
|
75
|
+
WHERE reality='R' and JSON_CONTAINS(attribe,'1')
|