回答編集履歴
1
調整
answer
CHANGED
|
@@ -7,4 +7,36 @@
|
|
|
7
7
|
where mei like '苗字%'
|
|
8
8
|
group by fullname
|
|
9
9
|
order by id
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
# sample
|
|
13
|
+
- 元データ
|
|
14
|
+
```SQL
|
|
15
|
+
create table tbl(
|
|
16
|
+
id int primary key,
|
|
17
|
+
sei varchar(100) null,
|
|
18
|
+
mei varchar(100) null
|
|
19
|
+
);
|
|
20
|
+
insert into tbl (id, sei, mei) VALUE
|
|
21
|
+
(1, '田中', '二郎'),
|
|
22
|
+
(2, '田中', '二郎2'),
|
|
23
|
+
(3, '田中', '二郎3'),
|
|
24
|
+
(4, '田中', '二郎4'),
|
|
25
|
+
(5, '高橋', '太郎'),
|
|
26
|
+
(6, '高橋', '太郎2'),
|
|
27
|
+
(7, '高橋', '太郎3'),
|
|
28
|
+
(8, '高橋', '太郎4'),
|
|
29
|
+
(9, '斎藤2', '一郎9'),
|
|
30
|
+
(10, '斎藤2', '一郎'),
|
|
31
|
+
(11, '斎藤2', '一郎2'),
|
|
32
|
+
(12, '斎藤2', '一郎3'),
|
|
33
|
+
(13, '斎藤2', '一'),
|
|
34
|
+
(14, '斎藤2', '一二三'),
|
|
35
|
+
(15, '斎藤2', '二郎');
|
|
36
|
+
```
|
|
37
|
+
- 抽出
|
|
38
|
+
```
|
|
39
|
+
select min(id) as id,concat(sei,substr(mei,1,1)) as fullname,count(*) as cnt from tbl
|
|
40
|
+
group by fullname
|
|
41
|
+
order by id
|
|
10
42
|
```
|