[英]Multiple Selects in Single Query
I'm hoping someone fluent in MySQL will be able to assist me with this. 我希望能说流利的MySQL的人能够为我提供帮助。 I'm trying to do a select on a select on a select, but the query doesn't seem to want to complete.
我正在尝试对选择进行选择,但是查询似乎不想完成。 Any help would be greatly appreciated.
任何帮助将不胜感激。
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
)
Try to use INNER JOINs instead of IN subqueries 尝试使用INNER JOINs代替IN子查询
UPD: I've edited this query according you comment. UPD:我已经根据您的评论编辑了此查询。 the first JOIN subquery output all
product
where both attributes exists and true. 第一个JOIN子查询输出两个属性都存在且为true的所有
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.