2014-12-01 4 views
0

의 다른 값은 내가그룹에 같은 분야

SELECT DISTINCT r.id_destination 
       , lo.location1 
       , lo.location2 
       , lo.destination 
       , lo.zip 
       , ld.id_field 
       , da.identification entity 
       , da.data 
      FROM pl_records r 
      JOIN pl_records_detail rd 
       ON r.id_order = rd.id_order 
     LEFT JOIN pl_attribue at 
       ON rd.product_attribute_id = at.id_product_attribute 
     LEFT JOIN pl_profile pr 
       ON at.id_attribute = pr.id_attribute 
      JOIN pl_location lo 
       ON r.id_address_delivery = lo.id_address 
      JOIN pl_situation si 
       ON r.current_state = si.id_order_state 
     LEFT JOIN pl_location_detail 
       ON r.id_cart = ld.id_cart 
     LEFT JOIN pl_data da 
       ON ld.id_field = da.id_field 
      WHERE r.id_record = 6 

쓴이 때문에 필드 "법인"과 "데이터"가 많은 값을 포함하기의 반복됩니다 출력을 반환하는 방법!

id_destination location1   location2 destination zip id_field entity data 
      55 east coast street ON  CN   454  28  89 Please process it with safe standards  
      55 east coast street ON  CN   454  28  90 Payment will be COD 
      55 east coast street ON  CN   454  28  78 updates not necessary 
      55 east coast street ON  CN   454  28  92 no withdrawal of details 
      55 east coast street ON  CN   454  28  99 added records 

값의 중복을 어떻게 방지 할 수 있습니까? 또는 가능한 방법 마지막 두 필드의 다른 값을 그룹화하는 방법

+0

하지만 실제로 중복되지는 않습니까? '데이터'는 매번 달라집니다. – Strawberry

답변

0

아마도 group_concat()을 찾고 계십니까?

SELECT r.id_destination, lo.location1, lo.location2, lo.destination, lo.zip, 
     GROUP_CONCAT(DISTINCT ld.id_field) as id_fields, 
     GROUP_CONCAT(DISTINCT da.identification) AS entities 
da.data 
FROM pl_records r JOIN 
    pl_records_detail rd 
    ON r.id_order = rd.id_order LEFT JOIN 
    pl_attribue at 
    ON rd.product_attribute_id = at.id_product_attribute LEFT JOIN 
    pl_profile p 
    ON at.id_attribute = pr.id_attribute JOIN 
    pl_location lo 
    ON r.id_address_delivery = lo.id_address JOIN 
    pl_situation si 
    ON r.current_state = si.id_order_state LEFT JOIN 
    pl_location_detail 
    ON r.id_cart = ld.id_cart LEFT JOIN 
    pl_data da 
    on ld.id_field = da.id_field 
WHERE r.id_record = 6 
GROUP BY r.id_destination, lo.location1, lo.location2, lo.destination, lo.zip 
+0

감사합니다. 이제는 쿼리에서 group_concat()를 사용하는 방법에 대해 알려 드리겠습니다. 신청서를 제출하고 결과가 양호해야한다. 다시 한 번 감사드립니다. – vicky