[英]How to merge two rows into a single row in mysql
The required table should merge two rows from the original table and the description in two rows should be appended into a single required table所需表应合并原始表中的两行,并将两行中的描述附加到单个所需表中
Original Table原表
id quantity item_number description unit_price Total returns
1 100 MISC SALES Misc Sales 0.3 30 ABC
2 NULL NULL XXXXXX NULL NULL ABC
3 200 MISC SALES Misc Sales 0.45 90 ABC
4 NULL NULL YYYYYY NULL NULL ABC
Required Table必填表
id quantity item_number description unit_price Total returns
1 100 MISC SALES Misc Sales XXXXXX 0.3 30 ABC
2 200 MISC SALES Misc Sales YYYYYY 0.45 90 ABC
select round(id/2),quantity,,item_number,GROUP_CONCAT(" " ,description) , unit_price,Total, returns
from (
select id,quantity,item_number, description, unit_price,Total, returns from table1 where id%2=1
UNION
select id-1,quantity,item_number, description ,unit_price,Total, returns from table1 where id%2=0
) as temp group by id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.