如题,订单表order(phone),订单商品表detail(order_id,goods_id,price_sell,amount),
现在要根据order表的一些字段和detail表里的字段查询订单信息,
如果只根据detail表里的goods_id查询那么DISTINCT 可以实现。现在的问题是,我要现实goods_id=1的小计金额(amount*price_sell)也显示出来,搞了好久不会,

解决方案 »

  1.   

    最简单的办法,写两个SELECT,一个详细的,一个小计的,然后UNION ALL在一起。
      

  2.   

    select* from a,b,(select goods_id,sum(amount)*price_sell from b group ) c where a.*=b.*,b.goodsid=c.goodsid
      

  3.   

    我简写的 ,提供一个思路而已。
    SELECT
    a.*, b.*, c.prices
    FROM ORDER a, detail b,
    (
    SELECT goods_id, sum(amount) * price_sell AS prices
    FROM
    detail GROUP
    ) c
    WHERE a.id = b.order_id and b.goods_id = c.goods_id