本帖最后由 yctcsms 于 2011-09-13 13:56:04 编辑

解决方案 »

  1.   

    select proid 商品编号,sum(salemoney) 销售金额, count(distinct orderid) 客户数 from B group by proid;
    这个查出来的客户数去除了重复项
      

  2.   

    客户数用错了,应该是 custid (同一客户可能有多张订单), 还要加上两表关联,补充一下select B.proid 商品编号,sum(B.salemoney) 销售金额, count(distinct A.custid) 客户数
        from A 
      INNER JOIN  B ON A.orderid = B.orderid
      group by B.proid;
      

  3.   

    一.不去除重复客户数.
    select proid,count(custid) ,sum(salemoney) from tbl a,tbl b where a.orderid=b.orderid 
    group by proid
    二.去除重复客户数
    select proid ,count(custid) ,sum(salemoney) from 
    (select proid,custid,sum(salemoney)  from tbl a,tbl b where a.orderid=b.orderid 
    group by proid,custid) group by proid