【发布时间】:2017-06-30 09:57:06
【问题描述】:
我有两张桌子:
prd_brand
- brand_id
- 姓名
catalog_product_entity_int
- attribute_id
- 行标识
- 价值
我加入这两个表如下:
SELECT main_table.*
FROM prd_brand AS main_table
INNER JOIN catalog_product_entity_int
ON main_table.brand_id=catalog_product_entity_int.value
group by brand_id
order by name asc
我现在要做的是检查catalog_product_entity_int 表,如果attribute_id 97 有value 1。如果它的值不是 1,则不要取它。
prd_brand
brand_id | name
26 | Nivea
44 | Ducray
catalog_product_entity_int
attribute_id | rowid | value
198 | 174 | 26
97 | 174 | 1
788 | 174 | 4
198 | 210 | 44
97 | 210 | 0
Nivea (ID 26) 存在于catalog_product_entity_int 表中,它的rowid 是174,这个rowid 在attribute_id 97 中有一个值1 => 我们接受它。
Ducray (ID 44) 存在于catalog_product_entity_int 表中,它的rowid 是210,这个rowid 在attribute_id 97 中的值为0 => 我们不接受它。
【问题讨论】:
-
发布一些示例数据和您的预期结果。
-
1) 使用
select *和group by查询是错误的。 2)具有预期输出的样本数据会有所帮助 -
@Forward : 请查看编辑后的示例
-
@OtoShavadze : 请参阅编辑后的示例
标签: mysql join where-clause