LEFT JOIN (
SELECT
product_id,
(t1.min_price * coalesce(t2.meta_value*80, t3.meta_value*80,1)) as minPrice,
(t1.max_price * coalesce(t2.meta_value*80, t3.meta_value*80,1)) as maxPrice
FROM
wp_wc_product_meta_lookup as t1
JOIN wp_term_relationships tr ON (t1.product_id = tr.object_id AND tr.term_taxonomy_id IN ( 83, 85 ) )
LEFT JOIN wp_postmeta as t2 ON tr.object_id = t2.post_id
AND t2.meta_key = 'convert_to_rub'
AND t2.meta_value = 1
LEFT JOIN wp_termmeta as t3 ON tr.term_taxonomy_id = t3.term_id
AND t3.meta_key = 'convert_to_rub'
AND t3.meta_value = 1
where t1.min_price > 0
) wc_product_meta_lookup ON (
wp_posts.ID = wc_product_meta_lookup.product_id
)
SELECT
wp_posts.ID,
wp_posts.post_title,
(wpml.min_price * coalesce(t2.meta_value*80, t3.meta_value*80,1)) minPrice,
(wpml.max_price * coalesce(t2.meta_value*80, t3.meta_value*80,1)) maxPrice
FROM
wp_posts
JOIN wp_wc_product_meta_lookup wpml ON (wp_posts.ID = wpml.product_id)
JOIN wp_term_relationships tr ON (wp_posts.ID = tr.object_id AND tr.term_taxonomy_id IN ( 83, 85 ) )
LEFT JOIN wp_postmeta as t2 ON (tr.object_id = t2.post_id
AND t2.meta_key = 'convert_to_rub'
AND t2.meta_value = 1)
LEFT JOIN wp_termmeta as t3 ON (tr.term_taxonomy_id = t3.term_id
AND t3.meta_key = 'convert_to_rub'
AND t3.meta_value = 1)
WHERE
1 = 1
AND wp_posts.post_type = 'product'
AND wpml.min_price > 0
--GROUP BY wp_posts.ID
ORDER BY wp_posts.post_name ASC
WITH Fruit as (
select 1 as id, '2,3,4' Similar union all
select 3 as id, '5,6,1,2' Similar
)
select Fruit_ID
from (
select
SUBSTRING_INDEX(SUBSTRING_INDEX(F.Similar , ',', numbers.n), ',', -1) Fruit_ID
from
(select 1 n union all select 2 union all select 3 union all select 4 union all select 5) numbers
join Fruit F on (CHAR_LENGTH(F.Similar )-CHAR_LENGTH(REPLACE(F.Similar , ',', ''))>=numbers.n-1)
group by Fruit_ID
) Fruit_S
left join (select id from Fruit) Fruit_I on (Fruit_S.Fruit_ID = Fruit_I.id)
where Fruit_I.id is null
SELECT
wp_posts.ID,
wp_posts.post_title,
(min_price * coalesce(t2.meta_value*80, t3.meta_value*80,1)) minPrice,
(max_price * coalesce(t2.meta_value*80, t3.meta_value*80,1)) maxPrice
FROM
wp_posts
JOIN wp_wc_product_meta_lookup wpml ON (wp_posts.ID = wc_product_meta_lookup.product_id)
JOIN wp_term_relationships tr ON (wp_posts.ID = tr.object_id AND tr.term_taxonomy_id IN ( 83, 85 ) )
LEFT JOIN wp_postmeta as t2 ON (tr.object_id = t2.post_id
AND t2.meta_key = 'convert_to_rub'
AND t2.meta_value = 1)
LEFT JOIN wp_termmeta as t3 ON (tr.term_taxonomy_id = t3.term_id
AND t3.meta_key = 'convert_to_rub'
AND t3.meta_value = 1)
WHERE
1 = 1
AND wp_posts.post_type = 'product'
AND wc_product_meta_lookup.minPrice > 0
--GROUP BY wp_posts.ID
ORDER BY wp_posts.post_name ASC
Напишите вот так: