Select SubID,Sum(Price) From mainTable a,subTable b 
       where a.SubID=b.Id Group by SubID

解决方案 »

  1.   

    select mainTable.id,subId,sum(price) from mainTable,subTable where mainTable.subId=subTable.id group by subId order by subTable.id asc;
      

  2.   

    select id ,title, Sumprice from subTable,
     (select subid ,sum(price) as Sumprice from maintablegroup by subid) B
     where subtable.id=B.subid order by id
      

  3.   

    select subTable.id as id ,title, Sumprice from subTable,
     (select subid ,sum(price) as Sumprice from maintablegroup by subid) B
     where subtable.id=B.subid order by id
      

  4.   

    select subid ,sum(price) as Sumprice from maintable group by subid order by subid
    subId就是subTable中的id,所以这样排序也是可以的.
      

  5.   

    select subid ,sum(price) as Sumprice from maintable group by subid order by subid