0
我使用下面的查詢來獲取多個表的計數: -從多個表以計數加入
SELECT
b.sales_title,
c.cat_name,
count(b.sales_id) as cnt,
count(e.comment_id) as coun
FROM tb_sale_report a
inner join tbl_sales b on a.sales_id=b.sales_id
inner join tb_category c on c.cat_id=b.category_id
left join tb_comment e on b.sales_id=e.sales_id
GROUP BY b.sales_title
我想實現
sales_title | cat_name | cnt | coun
--------------------------------------------------
Affiliate | Kids toys | 8 | 0
Date Check | Handbags | 26 | 1
Date Date | My Category | 4 | 1
Future Date | Handbags | 3 | 0
Giovanni | Kids toys | 4 | 1
但不是我我得到錯誤的計數,列coun
的值出現這樣的錯誤,
sales_title | cat_name | cnt | coun
---------------------------------------------
Affiliate | Kids toys | 8 | 0
Date Check | Handbags | 26 | 26
Date Date | My Category | 4 | 4
Future Date | Handbags | 3 | 0
Giovanni | Kids toys | 4 | 4
我如何編寫查詢來實現我的目標。需要幫助,我是編程的新手。提前感謝
非常感謝數學咖啡。這工作正常。 – 2012-02-10 06:28:40