SELECT ANAME,COUNT(BDATA) FROM 
(select B.ID BID,a.name ANAME,b.data BDATA from tab1 a,tab2 b where a.id=b.id) group by BID;

解决方案 »

  1.   

    select b.id,count(b.data) from tab1 a,tab2 b where a.id=b.id group by b.id;
      

  2.   

    同意楼上
    不能存在非group by的列
      

  3.   

    不是多表的問題,而是使用group by后,select的字段必須是group by的字段或者是聚集的
    select a.id,b.name,sum(sl) from a,b where a.id=b.id group by a.id,b.name
      

  4.   

    select a.name,(select count(data) from tab2 where id=a.id) from tab1 a;
      

  5.   

    select a.name,(select count(data) from tab2 where id=a.id) from tab1 a;
      

  6.   

    select a.name,count(*) from tab1 a,tab2 b where a.id=b.id group by a.name;