0

我有两张表,ProductsBundleProductsBaseProducts 有 o2o 关系。ABundleProductProducts使用 m2m 关系到Products表的集合。 Products有一个price列,a 的价格BundleProduct计算为其 的价格之和Products

BaseProducts有像这样的列namedescription所以我可以查询它来获取ProductsBundleProducts

是否可以同时查询和计算sort by priceprice列?ProductspriceBundleProducts

4

1 回答 1

1

尝试这样的事情:

SELECT name, description, price
FROM (
    SELECT name, description, price FROM products
    UNION
    SELECT bundle_products.name, bundle_products.description, sum(products.price)
    FROM bundle_products
    JOIN products on (<your join condition)
    GROUP BY bundle_products.name, bundle_products.description
) AS combined
ORDER BY price
于 2010-03-12T22:58:54.143 回答