Это должно работать после изменения имени таблицы. Трюк состоит в том, чтобы наращивать его поэтапно. Сначала соедините value_1
и value_2
, затем по общей сумме и введите с помощью ,
в качестве разделителя, а затем, по умолчанию, введите |
.
select type,
group_concat(distinct total separator '|') as total,
group_concat(distinct id separator '|') as id,
group_concat(distinct vals separator '|') as vals
from (select type,
group_concat(distinct total separator ',') as total,
group_concat(distinct id separator ',') as id,
group_concat(distinct vals separator ',') as vals,
count(id) as count
from (select id, total, type, concat(value_1,'-',value_2) as vals from tbl) as a
group by total, type order by count desc) as b
group by type;
Я реплицировать таблицу, чтобы я мог проверить его
mysql> select * from tbl;
+------+-------+------+---------+---------+
| id | total | type | value_1 | value_2 |
+------+-------+------+---------+---------+
| 1 | 9 | 1 | 10 | 20 |
| 2 | 9 | 1 | 21 | 30 |
| 3 | 10 | 1 | 31 | 40 |
| 4 | 9 | 2 | 41 | 50 |
| 5 | 9 | 2 | 51 | 60 |
| 6 | 8 | 2 | 61 | 70 |
+------+-------+------+---------+---------+
6 rows in set (0.00 sec)
Вот результат.
mysql> select type,
-> group_concat(distinct total separator '|') as total,
-> group_concat(distinct id separator '|') as id,
-> group_concat(distinct vals separator '|') as vals
-> from (select type,
-> group_concat(distinct total separator ',') as total,
-> group_concat(distinct id separator ',') as id,
-> group_concat(distinct vals separator ',') as vals,
-> count(id) as count
-> from (select id, total, type, concat(value_1,'-',value_2) as vals from tbl) as a
-> group by total, type order by count desc) as b
-> group by type;
+------+-------+-------+-------------------+
| type | total | id | vals |
+------+-------+-------+-------------------+
| 1 | 9|10 | 1,2|3 | 10-20,21-30|31-40 |
| 2 | 9|8 | 4,5|6 | 41-50,51-60|61-70 |
+------+-------+-------+-------------------+
2 rows in set, 1 warning (0.00 sec)
На данный момент я могу только запрос группы по общей, и я получил немного трудности при попытке группы по типу ВЫБРАТЬ \t всего, \t GROUP_CONCAT (идентификатор Separator «|») AS идентификатор , \t GROUP_CONCAT ( \t \t CONCAT_WS ( \t \t \t '-', \t \t \t значение_1 \t \t \t значение_2 \t \t) СЕПАРАТОР '|' \t) в качестве значения ОТ \t таблицы GROUP BY \t всего –