esistema1 Posted November 11, 2020 Report Share Posted November 11, 2020 Всем доброго дня! Прошу помощи... Сейчас на Яндекс маркет выводятся все товары которые есть в наличии (магазин одежды) по запросу SELECT v.price, v.compare_price, v.id as variant_id, p.name as product_name, v.name as variant_name, v.position as variant_position, v.sku AS variant_sku, p.id as product_id, p.url, p.annotation, pc.category_id, i.filename as image, b.name as brand, b.url as brand_url FROM s_variants v LEFT JOIN s_products p ON v.product_id=p.id LEFT JOIN s_products_categories pc ON p.id = pc.product_id AND pc.position=(SELECT MIN(position) FROM s_products_categories WHERE product_id=p.id LIMIT 1) LEFT JOIN s_images i ON p.id = i.product_id AND i.position=(SELECT MIN(position) FROM s_images WHERE product_id=p.id LIMIT 1) LEFT JOIN s_brands b ON p.brand_id = b.id WHERE p.visible AND v.price>100 AND (v.stock >0 OR v.stock is NULL) GROUP BY v.id ORDER BY p.id, v.position У товаров есть варианты, размеры, например 42, 44, 46, 48. Я хочу сделать чтобы на маркет выводились только те товары у которых в наличии более 3 вариантов товара (например 42, 46, 48). Я думаю что в результате вывода этого запроса надо посчитать одинаковые product_id и поставить условие на вывод >3. Подскажите пожалуйста как это сделать? Quote Link to post Share on other sites
phukortsin Posted November 11, 2020 Report Share Posted November 11, 2020 Примерно так AND (select count(*) FROM s_variants v2 WHERE v2.product_id=p.id AND (v2.stock >0 OR v2.stock is NULL) )>2 Quote Link to post Share on other sites
esistema1 Posted November 11, 2020 Author Report Share Posted November 11, 2020 Огромное спасибо, получилось! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.