回答編集履歴
2
追記
answer
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
declare cur cursor for
|
18
18
|
select a,b,c,d,e from tbl;
|
19
19
|
declare continue handler for sqlstate '02000' set done = 1;
|
20
|
-
set @a:=(select concat('`',group_concat(distinct d separator '` int null,`'),'` int null') from tbl);
|
20
|
+
set @a:=(select concat('`',group_concat(distinct d order by d asc separator '` int null,`'),'` int null') from tbl);
|
21
21
|
set @sql=concat('create temporary table tmp_tbl(`a` int,`b` int,`c` int,',@a,',unique(`a`,`b`,`c`))');
|
22
22
|
prepare stmt from @sql;
|
23
23
|
execute stmt;
|
1
修正
answer
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
効率的かどうかはともかく
|
1
|
+
効率的かどうかはともかく、せっかくなのでプロシージャでやる方法を提示しておきます。
|
2
2
|
テーブルの形式が明確ではないのでちょっと簡略化して表示します
|
3
3
|
|
4
4
|
```SQL
|
5
5
|
create table tbl(a int,b int,c int,d date,e int);
|
6
6
|
insert into tbl values(0,0,0,'2016-10-25',6),(0,0,0,'2016-10-26',2),(0,0,0,'2016-11-01',4),(0,0,1,'2016-10-25',6),(0,0,1,'2016-10-26',2),(0,0,2,'2016-10-26',2),(0,0,2,'2016-11-01',4)
|
7
7
|
```
|
8
|
-
以下
|
8
|
+
以下プロシージャを作ります
|
9
9
|
```sql
|
10
10
|
drop procedure if exists view;
|
11
11
|
delimiter //
|
@@ -37,6 +37,7 @@
|
|
37
37
|
```
|
38
38
|
|
39
39
|
プロシージャを実行します
|
40
|
+
データの追加削除をした後以下を実行すればその時々の状況が確認できます
|
40
41
|
```SQL
|
41
42
|
call view();
|
42
43
|
```
|