使用GROUP_CONCAT功能,但它意味着具有與基置換DISTINCT BY:
SELECT idx_campus_bookinfo,
GROUP_CONCAT(c.userid SEPARATOR ',') as Buyer,
bookname,
book_explain,
writedate
FROM campus_bookinfo cb
LEFT JOIN user_books ub ON idx_campus_bookinfo = id_product
LEFT JOIN customer c ON ub.id_customer = c.id_customer
WHERE cb.idx_campus = 1
AND cb.idxuser = 29
GROUP BY idx_campus_bookinfo, bookname, book_explain, writedate
ORDER BY writedate DESC
一個後續問題,我可以排序的用戶ID?
是的,你可以:
SELECT idx_campus_bookinfo,
GROUP_CONCAT(c.userid ORDER BY c.userid ASC SEPARATOR ',') as Buyer,
bookname,
book_explain,
writedate
FROM campus_bookinfo cb
LEFT JOIN user_books ub ON idx_campus_bookinfo = id_product
LEFT JOIN customer c ON ub.id_customer = c.id_customer
WHERE cb.idx_campus = 1
AND cb.idxuser = 29
GROUP BY idx_campus_bookinfo, bookname, book_explain, writedate
ORDER BY writedate DESC
...看來你打我吧;) – 2009-12-09 01:54:04
漂亮的一個主..這是我需要的..謝謝了一堆 – Treby 2009-12-09 01:54:59
一個後續問題,我可以排序的用戶ID? – Treby 2009-12-09 02:12:25