回答編集履歴
1
ちょうせい
test
CHANGED
@@ -56,4 +56,86 @@
|
|
56
56
|
|
57
57
|
|
58
58
|
|
59
|
+
# リレーション関連
|
60
|
+
|
61
|
+
```SQL
|
62
|
+
|
63
|
+
create table customers(
|
64
|
+
|
65
|
+
id varchar(30) primary key not null,
|
66
|
+
|
67
|
+
last_name varchar(10),
|
68
|
+
|
69
|
+
first_name varchar(10),
|
70
|
+
|
71
|
+
email varchar(50),
|
72
|
+
|
73
|
+
created_at datetime);
|
74
|
+
|
59
|
-
|
75
|
+
insert into customers values
|
76
|
+
|
77
|
+
('cus_G50Aw9QPAn5VjF','田中','かずお','ken@gmail.com','2019-10-29 17:34:27'),
|
78
|
+
|
79
|
+
('cus_G50esjtjdXCVSX','吉田','たろう','yoshida@gmail.com','2019-10-29 18:04:45'),
|
80
|
+
|
81
|
+
('cus_G50ImEgofoHIjr','山田','こうすけ','goo@gmail.com','2019-10-29 17:42:48'),
|
82
|
+
|
83
|
+
('cus_G50VgUaw2V2CZo','藤田','ニコル','show@gmail.com','2019-10-29 17:56:22');
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
create table transactions(
|
88
|
+
|
89
|
+
id varchar(30) primary key not null,
|
90
|
+
|
91
|
+
customer_id varchar(30),
|
92
|
+
|
93
|
+
subscription varchar(10),
|
94
|
+
|
95
|
+
amount int,
|
96
|
+
|
97
|
+
currentcy varchar(10),
|
98
|
+
|
99
|
+
status varchar(10),
|
100
|
+
|
101
|
+
create_at datetime);
|
102
|
+
|
103
|
+
insert into transactions values
|
104
|
+
|
105
|
+
('sub_G50eORaCOnTnJB','cus_G50esjtjdXCVSX','monthly','15000','jpy','active','2019-10-29 18:04:45'),
|
106
|
+
|
107
|
+
('sub_G50IlV2zUFSPNh','cus_G50ImEgofoHIjr','monthly','15000','jpy','active','2019-10-29 17:42:48'),
|
108
|
+
|
109
|
+
('sub_G50WH4OU89NMip','cus_G50VgUaw2V2CZo','monthly','15000','jpy','active','2019-10-29 17:56:22');
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
- ken@gmail.com
|
116
|
+
|
117
|
+
```SQL
|
118
|
+
|
119
|
+
SELECT customers.email AS email, transactions.id AS id FROM customers INNER JOIN transactions ON customers.id = transactions.customer_id WHERE customers.email = 'ken@gmail.com';
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
※結果:ヒットなし
|
124
|
+
|
125
|
+
- yoshida@gmail.com
|
126
|
+
|
127
|
+
```SQL
|
128
|
+
|
129
|
+
SELECT customers.email AS email, transactions.id AS id FROM customers INNER JOIN transactions ON customers.id = transactions.customer_id WHERE customers.email = 'yoshida@gmail.com';
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
※結果
|
136
|
+
|
137
|
+
|email|id|
|
138
|
+
|
139
|
+
|:--|:--|
|
140
|
+
|
141
|
+
|yoshida@gmail.com|sub_G50eORaCOnTnJB|
|