gpt4 book ai didi

mysql - 如何使用 Concat 进行 GROUP_CONCAT

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

Product name    supplier
A Su1
A Su1
A Su2
B Su1
C Su3

我想要这样

A - su1, A-su2, B-su1, C-su3

查询:

SELECT 
vtiger_salesorder.salesorder_no,

(Select
group_concat(DISTINCT concat(vtiger_products.productname, '-', vtiger_vendor.vendorname ) SEPARATOR ', ')
FROM
vtiger_salesorder
LEFT Join vtiger_inventoryproductrel ON vtiger_salesorder.salesorderid = vtiger_inventoryproductrel.id
inner Join vtiger_products ON vtiger_products.productid = vtiger_inventoryproductrel.productid
inner Join softMax_SalesOrderVendorInfo ON softMax_SalesOrderVendorInfo.salesorderid = vtiger_salesorder.salesorderid
LEFT JOIN vtiger_vendor ON softMax_SalesOrderVendorInfo.vendorid = vtiger_vendor.vendorid
where (vtiger_salesorder.salesorderid = vtiger_inventoryproductrel.id
AND vtiger_salesorder.salesorderid = vtiger_crmentity.crmid
and (softMax_SalesOrderVendorInfo.status = '0') )Group by vtiger_salesorder.salesorderid Limit 0,1) As SuName1

FROM
vtiger_salesorder
INNER JOIN vtiger_inventoryproductrel ON vtiger_salesorder.salesorderid = vtiger_inventoryproductrel.id
Inner Join vtiger_crmentity ON vtiger_salesorder.salesorderid = vtiger_crmentity.crmid
Order by vtiger_salesorder.salesorder_no

最佳答案

根据您的原始数据,您可以简单地执行以下操作:

select distinct group_concat(ProductName, '-', Supplier separator ', ')
from table t;

我不知道查询与问题有什么关系,因为您似乎已经拥有适当格式的数据。

关于mysql - 如何使用 Concat 进行 GROUP_CONCAT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28813296/

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