2003-07-06 17:11:19 +02:00
|
|
|
drop table if exists t1, t2;
|
2003-03-18 00:07:40 +01:00
|
|
|
create table t1 (grp int, a bigint unsigned, c char(10) not null, d char(10) not null);
|
|
|
|
insert into t1 values (1,1,"a","a");
|
|
|
|
insert into t1 values (2,2,"b","a");
|
|
|
|
insert into t1 values (2,3,"c","b");
|
|
|
|
insert into t1 values (3,4,"E","a");
|
|
|
|
insert into t1 values (3,5,"C","b");
|
|
|
|
insert into t1 values (3,6,"D","b");
|
|
|
|
insert into t1 values (3,7,"d","d");
|
|
|
|
insert into t1 values (3,8,"d","d");
|
|
|
|
insert into t1 values (3,9,"D","c");
|
|
|
|
select grp,group_concat(c) from t1 group by grp;
|
|
|
|
grp group_concat(c)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 b,c
|
|
|
|
3 E,C,D,d,d,D
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(a,c) from t1 group by grp;
|
|
|
|
grp group_concat(a,c)
|
|
|
|
1 1a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 2b,3c
|
|
|
|
3 4E,5C,6D,7d,8d,9D
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat("(",a,":",c,")") from t1 group by grp;
|
|
|
|
grp group_concat("(",a,":",c,")")
|
|
|
|
1 (1:a)
|
2003-04-15 20:22:43 +02:00
|
|
|
2 (2:b),(3:c)
|
|
|
|
3 (4:E),(5:C),(6:D),(7:d),(8:d),(9:D)
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(c separator ",") from t1 group by grp;
|
|
|
|
grp group_concat(c separator ",")
|
|
|
|
1 a
|
|
|
|
2 b,c
|
|
|
|
3 E,C,D,d,d,D
|
|
|
|
select grp,group_concat(c separator "---->") from t1 group by grp;
|
|
|
|
grp group_concat(c separator "---->")
|
|
|
|
1 a
|
|
|
|
2 b---->c
|
|
|
|
3 E---->C---->D---->d---->d---->D
|
|
|
|
select grp,group_concat(c order by c) from t1 group by grp;
|
|
|
|
grp group_concat(c order by c)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 b,c
|
|
|
|
3 C,D,d,d,D,E
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(c order by c desc) from t1 group by grp;
|
|
|
|
grp group_concat(c order by c desc)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 c,b
|
|
|
|
3 E,D,d,d,D,C
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(d order by a) from t1 group by grp;
|
|
|
|
grp group_concat(d order by a)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 a,b
|
|
|
|
3 a,b,b,d,d,c
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(d order by a desc) from t1 group by grp;
|
|
|
|
grp group_concat(d order by a desc)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 b,a
|
|
|
|
3 c,d,d,b,b,a
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(a order by a,d+c) from t1 group by grp;
|
|
|
|
grp group_concat(a order by a,d+c)
|
|
|
|
1 1
|
2003-04-15 20:22:43 +02:00
|
|
|
2 2,3
|
|
|
|
3 4,5,6,7,8,9
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(c order by 1) from t1 group by grp;
|
|
|
|
grp group_concat(c order by 1)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 b,c
|
|
|
|
3 C,D,d,d,D,E
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(c order by "c") from t1 group by grp;
|
|
|
|
grp group_concat(c order by "c")
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 b,c
|
|
|
|
3 C,D,d,d,D,E
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(distinct c order by c) from t1 group by grp;
|
|
|
|
grp group_concat(distinct c order by c)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 b,c
|
|
|
|
3 C,D,E
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(distinct c order by c desc) from t1 group by grp;
|
|
|
|
grp group_concat(distinct c order by c desc)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 c,b
|
|
|
|
3 E,D,C
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(c order by c separator ",") from t1 group by grp;
|
|
|
|
grp group_concat(c order by c separator ",")
|
|
|
|
1 a
|
|
|
|
2 b,c
|
|
|
|
3 C,D,d,d,D,E
|
|
|
|
select grp,group_concat(c order by c desc separator ",") from t1 group by grp;
|
|
|
|
grp group_concat(c order by c desc separator ",")
|
|
|
|
1 a
|
|
|
|
2 c,b
|
|
|
|
3 E,D,d,d,D,C
|
|
|
|
select grp,group_concat(distinct c order by c separator ",") from t1 group by grp;
|
|
|
|
grp group_concat(distinct c order by c separator ",")
|
|
|
|
1 a
|
|
|
|
2 b,c
|
|
|
|
3 C,D,E
|
|
|
|
select grp,group_concat(distinct c order by c desc separator ",") from t1 group by grp;
|
|
|
|
grp group_concat(distinct c order by c desc separator ",")
|
|
|
|
1 a
|
|
|
|
2 c,b
|
|
|
|
3 E,D,C
|
|
|
|
select grp,group_concat(c order by grp desc) from t1 group by grp order by grp;
|
|
|
|
grp group_concat(c order by grp desc)
|
|
|
|
1 a
|
2003-04-15 20:22:43 +02:00
|
|
|
2 c,b
|
|
|
|
3 D,d,d,D,C,E
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp, group_concat(a separator "")+0 from t1 group by grp;
|
|
|
|
grp group_concat(a separator "")+0
|
|
|
|
1 1
|
|
|
|
2 23
|
|
|
|
3 456789
|
|
|
|
select grp, group_concat(a separator "")+0.0 from t1 group by grp;
|
|
|
|
grp group_concat(a separator "")+0.0
|
|
|
|
1 1.0
|
|
|
|
2 23.0
|
|
|
|
3 456789.0
|
|
|
|
select grp, ROUND(group_concat(a separator "")) from t1 group by grp;
|
|
|
|
grp ROUND(group_concat(a separator ""))
|
|
|
|
1 1
|
|
|
|
2 23
|
|
|
|
3 456789
|
2003-04-02 13:55:53 +02:00
|
|
|
drop table t1;
|
2003-03-18 00:07:40 +01:00
|
|
|
create table t1 (grp int, c char(10));
|
|
|
|
insert into t1 values (1,NULL);
|
|
|
|
insert into t1 values (2,"b");
|
|
|
|
insert into t1 values (2,NULL);
|
|
|
|
insert into t1 values (3,"E");
|
|
|
|
insert into t1 values (3,NULL);
|
|
|
|
insert into t1 values (3,"D");
|
|
|
|
insert into t1 values (3,NULL);
|
|
|
|
insert into t1 values (3,NULL);
|
|
|
|
insert into t1 values (3,"D");
|
2003-04-02 13:55:53 +02:00
|
|
|
insert into t1 values (4,"");
|
|
|
|
insert into t1 values (5,NULL);
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(c order by c) from t1 group by grp;
|
|
|
|
grp group_concat(c order by c)
|
2003-04-02 13:55:53 +02:00
|
|
|
1 NULL
|
|
|
|
2 b
|
2003-04-15 20:22:43 +02:00
|
|
|
3 D,D,E
|
2003-04-02 13:55:53 +02:00
|
|
|
4
|
|
|
|
5 NULL
|
2003-03-18 00:07:40 +01:00
|
|
|
set group_concat_max_len = 5;
|
|
|
|
select grp,group_concat(c) from t1 group by grp;
|
|
|
|
grp group_concat(c)
|
2003-04-02 13:55:53 +02:00
|
|
|
1 NULL
|
|
|
|
2 b
|
2003-04-24 13:49:01 +02:00
|
|
|
3 D,D,E
|
2003-04-02 13:55:53 +02:00
|
|
|
4
|
|
|
|
5 NULL
|
2003-03-18 00:07:40 +01:00
|
|
|
Warnings:
|
2003-08-18 23:08:08 +02:00
|
|
|
Warning 1259 1 line(s) was(were) cut by group_concat()
|
2003-03-18 00:07:40 +01:00
|
|
|
show warnings;
|
|
|
|
Level Code Message
|
2003-08-18 23:08:08 +02:00
|
|
|
Warning 1259 1 line(s) was(were) cut by group_concat()
|
2003-05-31 11:44:19 +02:00
|
|
|
set group_concat_max_len = 1024;
|
2003-03-18 00:07:40 +01:00
|
|
|
select group_concat(sum(a)) from t1 group by grp;
|
2003-06-04 17:28:51 +02:00
|
|
|
ERROR HY000: Invalid use of group function
|
2003-03-18 00:07:40 +01:00
|
|
|
select grp,group_concat(c order by 2) from t1 group by grp;
|
2003-06-04 17:28:51 +02:00
|
|
|
ERROR 42S22: Unknown column '2' in 'group statement'
|
2003-05-31 11:44:19 +02:00
|
|
|
drop table t1;
|
2003-07-06 17:11:19 +02:00
|
|
|
create table t1 ( URL_ID int(11), URL varchar(80));
|
|
|
|
create table t2 ( REQ_ID int(11), URL_ID int(11));
|
|
|
|
insert into t1 values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
|
|
|
|
insert into t2 values (1,4), (5,4), (5,5);
|
|
|
|
select REQ_ID, Group_Concat(URL) as URL from t1, t2 where
|
|
|
|
t2.URL_ID = t1.URL_ID group by REQ_ID;
|
|
|
|
REQ_ID URL
|
|
|
|
1 X
|
|
|
|
5 X,X,X
|
2003-09-04 02:44:16 +02:00
|
|
|
select REQ_ID, Group_Concat(URL) as URL, Min(t1.URL_ID) urll,
|
2003-10-08 06:19:44 +02:00
|
|
|
Max(t1.URL_ID) urlg from t1, t2 where t2.URL_ID = t1.URL_ID group by REQ_ID;
|
2003-09-04 02:44:16 +02:00
|
|
|
REQ_ID URL urll urlg
|
|
|
|
1 X 4 4
|
|
|
|
5 X,X,X 4 5
|
2003-07-06 17:11:19 +02:00
|
|
|
drop table t1;
|
|
|
|
drop table t2;
|
2003-07-05 02:03:31 +02:00
|
|
|
create table t1 (id int, name varchar(16));
|
|
|
|
insert into t1 values (1,'longername'),(1,'evenlongername');
|
|
|
|
select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'without distinct: how it should be' from t1;
|
|
|
|
without distinct: how it should be
|
|
|
|
1:longername,1:evenlongername
|
|
|
|
select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1;
|
|
|
|
with distinct: cutoff at length of shortname
|
|
|
|
1:longername,1:evenlongername
|
|
|
|
drop table t1;
|
2003-09-04 02:44:16 +02:00
|
|
|
create table t1(id int);
|
|
|
|
create table t2(id int);
|
|
|
|
insert into t1 values(0),(1);
|
|
|
|
select group_concat(t1.id) FROM t1,t2;
|
|
|
|
group_concat(t1.id)
|
|
|
|
NULL
|
|
|
|
drop table t1;
|
|
|
|
drop table t2;
|
|
|
|
create table t1 (bar varchar(32));
|
|
|
|
insert into t1 values('test'),('test2');
|
|
|
|
select * from t1 having group_concat(bar)='';
|
|
|
|
bar
|
|
|
|
drop table t1;
|