0
classid、optionid、 'images'のリスト(4つのテーブルから)を生成しようとしています。各製品には多数のClassID(1対多)があり、各ClassIDには多くのOptionIDがあり、各OptionIDには多数の画像があります。最後に、イメージテーブル(xcart_images_D)については、各productIDが持つイメージの数を数えたいと思います。複数のステートメントを使用せずにすべての情報を効果的に照会するにはどうすればよいですか?カウントで3つのテーブル結合の問題
ここでは、テーブルの各
xcart_products
+ productid*
+ product
xcart_classes -
+ classid*
+ productid (xcart_products.productid)
xcart_class_options -
+ optionid*
+ classid (xcart_classes.classid)
+ option_name
xcart_images_D -
+ imageid*
+ optionid (xcart_class_options.optionid)
+ id (xcart_products.productid)
* primary/foreign key
のための基本的な情報があります私は3台が作業に参加していますが、私はxcart_images_Dテーブルを動作させることはできませんも私は数を達成する方法を理解してください。誰かが私を正しい方向に向けることができますか?それはここに価値がある何のため
は、私が試してみて、結果の数は約半分に減少している以下の行を追加すると私の3台が
SELECT xp.productid, xp.product, xc.classid, xco.optionid, xco.option_name
FROM xcart_products xp
JOIN xcart_classes xc ON xp.productid = xc.productid and xc.class = 'Color'
JOIN xcart_class_options xco ON xc.classid = xco.classid
WHERE xc.class = 'Color'
ORDER by xp.productid DESC
に参加しています。
JOIN xcart_images_D xi ON xi.optionid = xco.optionid
GROUP BY xp.productid
助けてくれてありがとう。 何らかの理由でカウントを追加すると、プルアップされた結果の数が2,000から約200に減少します。理由は何ですか? – Eric