1

我希望精通 MySQL 的人能够帮助我解决这个问题。我正在尝试对选择进行选择,但查询似乎不想完成。任何帮助将不胜感激。

SELECT 
    product as pid, 
    leg_name as name, 
    dimensions as dims 
FROM 
    pmaint 
WHERE 
    product in (
        SELECT product 
        FROM qb_export_items_attributes
        WHERE attribute_name = 'Z' 
        AND product in (
                SELECT product
                FROM pmainT
                WHERE type_ID = (
                        SELECT ID
                        FROM type
                        WHERE SOFTCARTCATEGORY = 'End Table Legs'
                    )
                )
        AND attribute_value <= 3.5
    )
4

1 回答 1

1

尝试使用 INNER JOINs 而不是 IN 子查询

UPD:我已根据您的评论编辑了此查询。第一个 JOIN 子查询输出所有product属性都存在且为真的地方。

SELECT 
    pmaint.product as pid, 
    pmaint.leg_name as name, 
    pmaint.dimensions as dims 
FROM 
    pmaint 
JOIN (select product from qb_export_items_attributes
       where ((attribute_name = 'Z') and (attribute_value <= 3.5))
             OR
             ((attribute_name = 'top_square') and (attribute_value >= 4))
       GROUP BY product HAVING COUNT(*)=2
      ) 

         t1 on (pmaint.product=t1.product )
JOIN type on (pmaint.type_ID=type.ID)
WHERE 
        type.SOFTCARTCATEGORY = 'End Table Legs'
于 2013-03-06T05:49:03.690 回答