gpt4 book ai didi

SQL 优化

转载 作者:行者123 更新时间:2023-11-29 01:18:59 31 4
gpt4 key购买 nike

如何优化这个?

SELECT e.attr_id, e.sku, a.value

FROM product_attr AS e, product_attr_text AS a

WHERE e.attr_id = a.attr_id
AND value
IN (
SELECT value
FROM product_attr_text
WHERE attribute_id = (
SELECT attribute_id
FROM eav_attr
WHERE attribute_code = 'similar_prod_id'
)
AND value != ''

GROUP BY value
HAVING (COUNT( value ) > 1 )
)

最佳答案

SELECT  e.attr_id, e.sku, a.value
FROM (
SELECT pat.value
FROM eav_attr ea
JOIN product_attr_text pat
ON pat.attribute_id = ea.attribute_id
WHERE ea.attribute_code = 'similar_prod_id'
AND value <> ''
GROUP BY
value
HAVING COUNT(*) > 1
) q
JOIN product_attr_text AS a
ON a.value = q.value
JOIN product_attr AS e
ON e.attr_id = a.attr_id

创建索引:

 eav_attr (attribute_code)
product_attr_text (attribute_id, value)
product_attr_text (value)
product_attr (attr_id)

关于SQL 优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4042721/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com