我有一个有几行的mysql结果集,我想要做的是根据行的唯一性将行组合起来形成一行结果。说我有这个:
表结果1
Labref | Medium_Day | Comonent | Generic_results
-------------------------------------------------
A | 1 | ab | A=5
-------------------------------------------------
A | 1 | ab | R=10
-------------------------------------------------
A | 1 | ab | N=5
-------------------------------------------------
A | 7 | cd | A=7
-------------------------------------------------
A | 7 | cd | R=6
-------------------------------------------------
A | 7 | cd | N=3
-------------------------------------------------
我想生产这样的东西
Labref | Medium_Day | Comonent | Generic_results
-------------------------------------------------
A | 1 | ab | A=5% (R10, N=5)
-------------------------------------------------
A | 7 | cd | A=7% (R=6, N=3)
-------------------------------------------------
我试图使用普通" SELECT * FROM component_summary
WHERE labref
=' A'"然后在应用程序端使用一个函数来执行此操作,但它不起作用...
任何建议首先使用mysql
答案 0 :(得分:0)
尝试此查询。
SELECT Labref, Medium_Day, Comonent,
CONCAT(
SUBSTRING_INDEX(GROUP_CONCAT(Generic_results), ',', 1),
'% (',
SUBSTRING_INDEX(GROUP_CONCAT(Generic_results), ',', 2),
',',
SUBSTRING_INDEX(GROUP_CONCAT(Generic_results), ',', 3),
')'
) AS gen_results
FROM component_summary
GROUP BY Labref