0

これが私の質問です:

 SELECT 
    O.OrderId,
    O.Number,
    (SELECT 
            CONCAT(A.Detail, ' ', C.Name, ' / ', Ci.Name)
        FROM
            kobiakinlar.Address AS A
                INNER JOIN
            County AS C ON C.CountyId = A.CountyId
                INNER JOIN
            City AS Ci ON C.CityId = Ci.CityId
        WHERE
            UserId = O.UserId) AS UserAddress,
    (SELECT 
            CASE
                    WHEN O.Status = 0 THEN 'Onay Bekliyor'
                    WHEN O.Status = 1 THEN 'Onaylandı'
                    WHEN O.Status = 2 THEN 'Reddedildi'
                END
        ) Status,
    O.Creation,
    (SELECT 
            CASE
                    WHEN O.IsDelivered = 0 THEN 'Teslim Edilmedi'
                    ELSE 'Teslim Edildi'
                END
        ) IsDelivered,
    SUM(T.Price) Price,
    GROUP_CONCAT(T.NAME) Products
FROM
    kobiakinlar.order O
        INNER JOIN
    (SELECT  
        P.Name, op.OrderId, op.Price
    FROM
        kobiakinlar.product P
    JOIN kobiakinlar.orderproduct op ON op.ProductId = P.productId
 ) T ON O.orderId = T.orderId
        INNER JOIN
    address A ON A.AddressId = O.AddressId

それは戻ります:

ここに画像の説明を入力してください

しかし、私はこれを試してみたいです:

ここに画像の説明を入力してください

私は何をすべきか?何か提案はありますか?

4

2 に答える 2

0

必要な構文は次のとおりです。

group_concat(distinct t.name separator ',') as Products
于 2012-11-12T15:15:07.193 に答える
0

私はこれで私のケルトを変更しました:

    SELECT op.OrderId,
    O.Number,    
    SUM(op.Price) Price,
    (SELECT CONCAT(A.Detail, ' ',C.Name, ' / ', Ci.Name) FROM kobiakinlar.Address AS A
                INNER JOIN County AS C ON C.CountyId = A.CountyId
                INNER JOIN City AS Ci ON C.CityId = Ci.CityId
                WHERE UserId = O.UserId) AS UserAddress,
   ( SELECT CASE WHEN O.Status =0 THEN 'Onay Bekliyor'  WHEN O.Status =1 THEN 'Onaylandı' WHEN O.Status = 2 THEN 'Reddedildi' END) Status,
    O.Creation,
    ( SELECT CASE WHEN O.IsDelivered =0 THEN 'Teslim Edilmedi' ELSE 'Teslim Edildi' END) IsDelivered,
    group_concat(P.Name) Product
FROM
    kobiakinlar.product P
        JOIN
    kobiakinlar.orderproduct op ON op.ProductId = P.productId
        JOIN
    kobiakinlar.order O ON O.orderId = op.OrderId
   JOIN 
kobiakinlar.address A ON A.addressId = O.AddressId
GROUP BY op.OrderId
于 2012-11-12T16:00:50.343 に答える