Py学习  »  DATABASE

MySQL-GROUP_CONCAT,具有来自不同表的两列

IlludiumPu36 • 5 年前 • 1665 次点击  

我要将当前组CONCAT中不同表中的两列连接起来:

SELECT MAX(unit.unit_pk) AS unit_pk,
       GROUP_CONCAT(unit_outcome.unit_outcome SEPARATOR '|') unit_outcomes,
       MAX(program_outcome.program_outcome) program_outcome,
       GROUP_CONCAT(unit_outcome.unit_outcome_pk) unit_outcome_pks, 
       program_outcome.program_outcome_pk,
       program_outcome.program_outcome
FROM unit
INNER JOIN unit_unit_outcome_lookup
    ON unit_unit_outcome_lookup.unit_fk = unit.unit_pk
INNER JOIN unit_outcome
    ON unit_outcome.unit_outcome_pk = unit_unit_outcome_lookup.unit_outcome_fk
INNER JOIN program_outcome_unit_outcome_lookup
    ON program_outcome_unit_outcome_lookup.unit_outcome_fk = unit_outcome.unit_outcome_pk
INNER JOIN program_outcome
    ON program_outcome.program_outcome_pk = program_outcome_unit_outcome_lookup.program_outcome_fk
GROUP BY program_outcome_pk ORDER BY program_outcome.program_outcome ASC

以便

GROUP_CONCAT(unit_outcome.unit_outcome SEPARATOR '|') unit_outcomes

unit.unit_code unit_outcome.unit_outcome 在里面 GROUP_CONCAT

我要找的结果是一个来自组CONCAT的字符串,比如“unit-code:unit-outcome”

db fiddle

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56457
 
1665 次点击  
文章 [ 1 ]  |  最新文章 5 年前