gpt4 book ai didi

mysql - 仅显示 mysql 中两列中的不同值

转载 作者:行者123 更新时间:2023-11-29 17:23:25 24 4
gpt4 key购买 nike

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

但是我的输出应该是这样的

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

最佳答案

您可以像这样使用group_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

关于mysql - 仅显示 mysql 中两列中的不同值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51114146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com