このクエリのほとんどは、2 つの大きな問題を除いて処理されました。1 つ目は、4 番目のテーブル [ departments_tbl ] をクエリに追加するとすぐに、約 100 行しかないはずのときに約 8K 行が返されます。
添付のスキーマを参照してください。チェックマークはありません。これらは返してほしいフィールドです。
これは役に立ちませんが、[department_tbl がミックスに追加されるまで] 私がほとんど作業していたクエリの 1 つにすぎません。
SELECT _n_cust_entity_storeid_15.entity_id,
_n_cust_entity_storeid_15.email,
customer_group.customer_group_code,
departments.`name`,
departments.manager,
_n_cust_rpt_copy.first_name,
_n_cust_rpt_copy.last_name,
_n_cust_rpt_copy.last_login_date,
_n_cust_rpt_copy.billing_address,
_n_cust_rpt_copy.billing_city,
_n_cust_rpt_copy.billing_state,
_n_cust_rpt_copy.billing_zip
FROM _n_cust_entity_storeid_15 INNER JOIN customer_group ON _n_cust_entity_storeid_15.group_id = customer_group.customer_group_id
INNER JOIN departments ON _n_cust_entity_storeid_15.store_id = departments.store_id,
_n_cust_rpt_copy
ORDER BY _n_cust_rpt_copy.last_name ASC
サブクエリ、結合を試しましたが、うまくいきません。
どんな助けでも大歓迎です。
スキーマ entity_idフィールドとcust_idフィールドは、 _ncust_rpt_copy テーブルと_n_cust_entity_storeid_15 tbl の間のリンクになることに注意してください。