0

我有两张桌子:

  1. product_session
  2. product_sale

product_sessionproduct_sale映射product_session_id,这是主键product_session和外来的product_sale

product_sale可以针对product_session_id.

product_sale有 4 列:

  • product_sale_id
  • product_session_id
  • sales1
  • sales2.

现在我需要一个查询,它将返回第一个表(product_sessionproduct_session_idsum(sales1),sum(sales2)第二个表(product_sale)的所有列,如果product_sale有多行反对product_session_id

4

1 回答 1

1
SELECT   product_session.*, SUM(product_sale.sales1), SUM(product_sale.sales2)
FROM     product_session LEFT JOIN product_sale USING (product_session_id)
GROUP BY product_session_id
于 2012-06-05T09:21:45.087 回答