简体   繁体   English

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

[英]Mysql - how to show value into same row from different column with condition

below is my code, 下面是我的代码,

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

Result: 结果:

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

but how to make/show if same session_id the error_code will mix in 1 row and remove empty like below, and same into tmp table? 但是如何使/显示是否相同的session_id的error_code将混合在1行中并删除空,如下所示,并且相同到tmp表?

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

i tried with GROUP_CONCAT or If condition but still not able to get the result i want :- 我尝试使用GROUP_CONCAT或If条件,但仍然无法获得我想要的结果:-

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

Get rid of distinct and use group by 摆脱不同之处并使用分组依据

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在特定表列上显示PHP在MySQL上的行内容(不同表上的.row名称相同) - Show MySQL row content on PHP from specific table column (same .row name on different tables) MYSQL:条件基于相同的表,不同列中的相同值 - MYSQL: Condition based on the same table, the same value in a different column MySQL在其他列中为每个不同的值显示具有最新日期的行? - MySQL show the row with the latest Date for each different value in other column? MySQL从同一行的不同列中选择最后输入的日期和值 - MySQL select last input date and value from same row different column MYSQL - 从不同的行中获取值并将它们返回到同一行 - MYSQL - Grab value from different row and return them on the same row 在mysql中,如何仅选择一列中具有相同值但在另一列中具有不同值的每一行? - In mysql, how do I select ONLY every row that has the same value in one column but different ones in another? 在一次查询中从不同条件两次从同一列获取值 - Obtain value from same column twice with different condition in single query 从 mysql 中具有相同值的每一行计算重复值 - Count repeated value from a column for each row with same value in mysql MySQL合并同一行中不同表的列 - MySQL merge column from different table in same row 从MySQL的同一列中选择两个不同的值并显示结果 - Select Two different values from the same column in MySQL and show results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM