在mysql的两列中只显示不同的值

在mysql的两列中只显示不同的值,mysql,mysql-workbench,Mysql,Mysql Workbench,电流输出 SELECT DISTINCT (CONCAT_WS('~', t5.component, t5.value)) AS inv_component, CONCAT_WS('~', t6.component, t6.value) AS comp_component FROM tds_salary_table t4 LEFT JOIN tds_investment_table t5 ON t4.employee_code = t5.employee_co

电流输出

SELECT 
    DISTINCT (CONCAT_WS('~', t5.component, t5.value)) AS inv_component,
    CONCAT_WS('~', t6.component, t6.value) AS comp_component    
FROM tds_salary_table t4 
    LEFT JOIN tds_investment_table t5 ON t4.employee_code = t5.employee_code
    LEFT JOIN tds_computation_table t6 ON t4.employee_code = t6.employee_code   
WHERE  
    t4.employee_code = 'E03135' AND t4.status !='2'AND t5.status !='2' AND t6.status !='2' 
GROUP BY inv_component, comp_component
但是我的输出应该是这样的

Value1                             value2

PPF DEPOSIT~2000.00    ADD: EDUCATION + HEALTH CESS 4%~10000.00
PPF DEPOSIT~2000.00    BALANCE TAX PAYABLE~12.00
PPF DEPOSIT~2000.00    DEDUCTION U/S 80 C~5000.00
PROVIDENT FUND~1000.00     ADD: EDUCATION + HEALTH CESS 4%~10000.00
PROVIDENT FUND~1000.00     BALANCE TAX PAYABLE~12.00
PROVIDENT FUND~1000.00     DEDUCTION U/S 80 C~5000.00

您可以像这样使用group_concat:

Value1                             value2

PPF DEPOSIT~2000.00    ADD: EDUCATION + HEALTH CESS 4%~10000.00
PROVIDENT FUND~1000.00     BALANCE TAX PAYABLE~12.00
Null                      DEDUCTION U/S 80 C~5000.00

您应该使用groupconcat而不是concat
SELECT 
    DISTINCT (CONCAT_WS('~', t5.component, t5.value)) AS inv_component,
    GROUP_CONCAT(CONCAT_WS('~', t6.component, t6.value)) AS comp_component    
FROM tds_salary_table t4 
    LEFT JOIN tds_investment_table t5 ON t4.employee_code = t5.employee_code
    LEFT JOIN tds_computation_table t6 ON t4.employee_code = t6.employee_code   
WHERE  
    t4.employee_code = 'E03135' AND t4.status !='2'AND t5.status !='2' AND t6.status !='2' 
GROUP BY inv_component