2015-03-02 43 views
0
Product name supplier 
A    Su1 
A    Su1 
A    Su2 
B    Su1 
C    Su3 

我想這樣如何使用的毗連

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

查詢GROUP_CONCAT:

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 
+0

您還沒有發佈任何問題。你想做什麼?你到目前爲止有多遠?你使用的是什麼數據?你有什麼*特定*問題?您發佈的查詢與帖子的其餘部分有何關係? – Jonny 2015-03-02 15:35:24

回答

0

鑑於你的原始數據,你可以簡單地做到這一點的東西,如:

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

我不知道這個查詢與什麼有關問題,因爲你似乎已經有了適當格式的數據。

+0

我試過但沒有工作 – user3428559 2015-03-03 05:33:36