MySQL:连接多列值的条件

时间:2012-09-09 14:12:08

标签: mysql jointable

以下是查询:

    SELECT CONCAT(imp_us_storefront.model,'/',imp_us_storefront.chassis) AS rec_desc, 1 AS flag,asc_model.model_id AS model,asc_chassis.chassis_id AS chassis
    FROM imp_us_storefront 
      JOIN asc_model ON (asc_model.rec_desc = imp_us_storefront.model)
      JOIN asc_chassis ON (asc_chassis.rec_desc = imp_us_storefront.chassis)
      JOIN attr_notebook ON (asc_model.model_id != attr_notebook.model_id AND asc_chassis.chassis_id != attr_notebook.chassis_id)
    WHERE imp_us_storefront.mri_category = '11946'
    GROUP BY rec_desc ASC;

对于此特定类别'11946',所有chassis_id都具有相同的值,因此结果集为空。如果我消除了约束

    asc_chassis_chassis_id != attr_notebook.chassis_id

然后我得到了我需要的结果,但这不适用于其他类别。所以我的问题是如何转换这一行

    JOIN attr_notebook ON (asc_model.model_id != attr_notebook.model_id AND asc_chassis.chassis_id != attr_notebook.chassis_id)

仅消除model_id和chassis_id的特定组合,以便如果我有以下值

MODEL_ID chassis_id

2 6

3 6

我可以消除2,6而不是3,6

OR

MODEL_ID chassis_id

4 2

4 3

我可以消除4,2而不是4,3?

提前致谢。

0 个答案:

没有答案