有这样两个表
A表
recordID(记录ID)  money(钱数)  optDate(操作日期)
B表
recordID(记录ID)  actID(活动ID) poundage(手续费)现在要按天进行统计 人数,钱数,手续费,根据optDate进行按天统计,关联关系:A.recordID=B.actID
因为手续费在B表里,怎样统计?

解决方案 »

  1.   

    ??  人数??? 表关联一下取不就有啦?:select A.recordID(记录ID)  money(钱数)  optDate(操作日期),
    (select sum(B.poundage(手续费)) 
     where A.recordID(记录ID) = actID(活动ID) 
    group by b.actID(活动ID)) as 手续费  from table A 
      

  2.   

    select a1.dayVarchar as 天数, sum(a1.money) as 钱数,sum(a1.actID) as 手续费
           /** 人数根据哪个字段取值呢?*/
    from(
     select A.recordID, A.money, to_char(A.optDate,'yyyy-mm-dd') as dayVarchar
            B.actID, 
     from A, B
     where A.recordID=B.actID    
    )a1 group by a1.dayVarchar