Einzelnen Beitrag anzeigen
  #2  
Alt 20.07.2011, 09:57:54
Matthias Matthias ist offline
Moderator
 
Registriert seit: Jan 2002
Ort: CologneCity
Alter: 46
Beiträge: 484
AW: Hilfe mit count bzw. sum

Du musst noch definieren nach was gruppiert werden soll. Schau dir mal group by an.

Deine Query sollte so das richtige Ergebnis liefern:

Code:
SELECT 
pc.`id_product_comment`, 
sum(if(hp.helpful=1,1,0)) AS helpful,
IF(c.id_customer, CONCAT(c.`firstname`, ' ', LEFT(c.`lastname`, 1)), pc.customer_name) customer_name, 
pc.`content`, 
pc.`grade`, 
pc.`date_add`, 
pc.title 
FROM `ps_product_comment` pc 
LEFT JOIN `ps_customer` c ON c.`id_customer` = pc.`id_customer` 
LEFT JOIN `wr_comment_helpful` hp ON ( pc.`id_product_comment` = hp.`id_product_comment`) 
WHERE pc.`id_product` = 11
GROUP BY pc.`id_product_comment` 
ORDER BY pc.`date_add` DESC
Mit Zitat antworten