gpt4 book ai didi

Mysql-如何根据条件将不同列的值显示到同一行

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

下面是我的代码,

select DISTINCT C.session_id,C.status,C.uut_serial_num,D.error_code from 

(Select A.*

From uut_info A, session_info B

Where A.session_id=B.session_id

And A.uut_serial_num ="ACNW6676"
and A.status ="Fail"
And B.test_spec<>'DBG'

Order By A.timestamp Desc

LIMIT 0,4) C left join subtest_info D

on C.uut_serial_num = D.uut_serial_num
and C.session_id = D.session_id

order by C.timestamp Desc

结果:

session_id              status  uut_serial_num  error_code
7385122219fa35c37942511 Fail ACNW6676 500004
7385122219fa35c37942511 Fail ACNW6676 40555
7385122219fa35c37942511 Fail ACNW6676 40187
7385122219fa35c37942511 Fail ACNW6676
412afc12a33601011721415 Fail ACNW6676
412afc12a33601011721415 Fail ACNW6676 100001
9213232191116c821a59f86 Fail ACNW6676
9213232191116c821a59f86 Fail ACNW6676 500005
11809c9a3382624993f5104 Fail ACNW6676 40187
11809c9a3382624993f5104 Fail ACNW6676
11809c9a3382624993f5104 Fail ACNW6676 40143
11809c9a3382624993f5104 Fail ACNW6676 500005

但是如何制作/显示如果相同的 session_id 错误代码将混合在 1 行中并像下面一样删除空,并且相同到 tmp 表?

    session_id          status  uut_serial_num  error_code
7385122219fa35c37942511 Fail ACNW6676 500004,40555,40187

我尝试使用 GROUP_CONCAT 或 If 条件,但仍然无法获得我想要的结果:-

select DISTINCT C.session_id,C.status,C.uut_serial_num,GROUP_CONCAT(D.error_code) from

最佳答案

摆脱distinct并使用group by

Select your_columns, 
group_concat(d.error_code) from
your_table group by session_id;

关于Mysql-如何根据条件将不同列的值显示到同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51316976/

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