select  t_trade.price,t_trade.tradename,sum(t_orderdish.amount) as total_amount,sum(t_trade.price) as total_price from t_orderdish,t_trade where t_orderdish.tableindex='"&tableindex&"' 
and t_orderdish.tradeid=t_trade.tradeid
GROUP BY t_trade.price,t_trade.tradenameUnion  all
Select 9999,'合计',999,sum(t_trade.price) from t_trade

解决方案 »

  1.   

    简单的说就是要把返回的totalprice全部加起来~
      

  2.   

    to txlicenhe(马可):小弟是初学者,实在不明白您的这句
    Union  all
    Select 9999,'合计',999,sum(t_trade.price) from t_trade
    我的意思是在我的这个sql句中既要求出sum(t_trade.price) as total_price 
    又要求出sum(total_price)
    郁闷之极...
      

  3.   

    select  t_trade.price,t_trade.tradename,sum(t_orderdish.amount) as total_amount,sum(t_trade.price) as total_price 
    from t_orderdish,t_trade where t_orderdish.tableindex='"&tableindex&"' 
    and t_orderdish.tradeid=t_trade.tradeid
    GROUP BY t_trade.price,t_trade.tradename
    union 
    select 0,'',0,sum(t_trade.price) as total_price 
    from t_orderdish,t_trade where t_orderdish.tableindex='"&tableindex&"' 
    and t_orderdish.tradeid=t_trade.tradeid
      

  4.   

    select  t_trade.price,t_trade.tradename,sum(t_orderdish.amount) as total_amount,
    sum(t_trade.price) as total_price,
    @totalprice=@totalprice+sum(t_trade.price)
     from t_orderdish,t_trade where t_orderdish.tableindex='"&tableindex&"' 
    and t_orderdish.tradeid=t_trade.tradeid
    GROUP BY t_trade.price,t_trade.tradename
      

  5.   

    在你那个SQL语句中不可能既求出sum(t_trade.price) as total_price,又求出sum(total_price)因为他是按t_trade.price,t_trade.tradename分组的
    用union 是把两个结果集合并为一个