现在有产品表
productid     产品ID 
name   产品名
username 发布产品人的用户名现在已经用sql语句做了一些处理,每一个username,只出来一个一个产品,即id和username都是唯一的现在又有留言表creditcreditid 留言ID
username 被留言的用户的用户名
title 留言的题目我现在想统计,某个产品所属于公司,现在有几条发给他的留言.

解决方案 »

  1.   

    能否写详细点,我地方用right更不行了,数字全部乱了
      

  2.   

    id     name       username 
    1      light      tashiro
    2      pen        kando
    以上product表
    creditid username title 
    1         tashiro "okokokok"
    2         tashiro "good good"
    3         kanodo  "bad bad"以上credit表那么我想出现这样id     name       username titileTotal
    1      light      tashiro  2
    2      pen        kando    1这样
      

  3.   

    selec a.id,a.name,a.username,titileTotal from product a left jion (
    select username,count(*) as titileTotal from credit group by username) as b 
    on a.name=b.username