MySQL-如何在有条件的情况下将值从不同的列显示到同一行

时间:2018-07-13 02:43:45

标签: mysql

下面是我的代码,

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的error_code将混合在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

1 个答案:

答案 0 :(得分:0)

摆脱不同之处并使用分组依据

test<-list(c("hello", "world", "!"), c("Nice","to","meet","you"))
print(clean.data(test))
> print(clean.data(test))
  value
1 hello
2 world
3     !
4  Nice
5    to
6  meet
7   you