質問

私はBaseProductsとO2O関係を持つ2つのテーブル、ProductsBundleProductsを持っています。 BundleProductProductsテーブルにM2M関係を使用してProductsのコレクションです。 Productsprice列を持っているとBundleProductの価格は、そのProductsの価格の合計として計算されます。

BaseProducts nameと私はdescriptionProductsの両方を得るためにそれを照会することができるようBundleProductsのような列を持っています。

これはsort by pricepriceの列とProductsの計算priceの両方を照会し、BundleProductsすることは可能ですか?

役に立ちましたか?

解決

このような何かを試してみてください。

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