我有两个表, ProductsBundleProducts 有o2o关系BaseProducts.一个 BundleProduct 是的集合 Products 使用m2m关系 Products 表。Products 有一个 price 柱和价格的 BundleProduct 是总数来计算的价格 Products.

BaseProducts 有列像 namedescription 所以我可以查询这得到两个 ProductsBundleProducts.

是否有可能查询和 sort by price 两对 priceProducts 和计算 priceBundleProducts?

有帮助吗?

解决方案

试试这样的事情:

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top