1064 -

select * FROM( select DISTINCT p.products_price * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) as priceWithTax, p.products_image, IF(p.id_product_grouper, mpg.product_name, pd.products_name) as products_name, if(pd.products_alt_image != '', pd.products_alt_image, pd.products_name) as products_alt_image, p.products_id, p.products_quantity, p.products_ignore_stock, p.manufacturers_id, p.products_label_id, p.products_price, p.products_price_b, p.products_price_c, p.products_tax_class_id, p.order_in_grouper as order_ig, IF(s.status, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) AS final_price, s.percentage, IF(p.id_product_grouper, CONCAT('g_', p.id_product_grouper), p.products_id) as group_id, (p.id_product_grouper is NULL) as grouper, CONCAT(cd.url_amigable, '/', IF(cd2.url_amigable IS NOT NULL, CONCAT(cd2.url_amigable,'/'), ''), IF(cd3.url_amigable IS NOT NULL, CONCAT(cd3.url_amigable, '/'), ''), pd.url_amigable,'.html') AS urlProducto, cd.categories_name as categoria, m.manufacturers_name , concat('-', group_concat(CONCAT(pa.options_id, '_',pa.options_values_id , '_', pa.options_value_text) SEPARATOR '-'), '-') options_values FROM products_description pd, products p LEFT JOIN products_attributes pa on pa.products_id = p.products_id left join tax_rates tr on p.products_tax_class_id = tr.tax_class_id left join zones_to_geo_zones gz on tr.tax_zone_id = gz.geo_zone_id and (gz.zone_country_id is null or gz.zone_country_id = '0' or gz.zone_country_id = '10') and (gz.zone_id is null or gz.zone_id = '0' or gz.zone_id = '169') LEFT JOIN mods_product_groupers mpg ON p.id_product_grouper = mpg.id LEFT JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id LEFT JOIN specials s ON p.products_id = s.products_id, categories c LEFT JOIN categories_description cd ON cd.categories_id = c.categories_id LEFT JOIN categories c2 ON c.categories_id = c2.parent_id LEFT JOIN categories_description cd2 ON cd2.categories_id = c2.categories_id LEFT JOIN categories c3 ON c2.categories_id = c3.parent_id LEFT JOIN categories_description cd3 ON cd3.categories_id = c3.categories_id LEFT JOIN products_to_categories p2c ON ( c.categories_id = p2c.categories_id OR c2.categories_id = p2c.categories_id OR c3.categories_id = p2c.categories_id) WHERE p.products_status = '1' AND p.products_id = p2c.products_id AND p.deleted = 0 AND pd.products_id = p2c.products_id AND pd.language_id = '2' AND c.categories_id = '249' and (c.hide_without_stock = 0 or p.products_quantity > 0 or p.products_ignore_stock = 1) AND m.manufacturers_id = 6 group by p.products_id having ORDER BY products_quantity DESC, order_ig ASC ) as tabla group by group_id ORDER BY CASE WHEN products_quantity < 1 THEN 0 WHEN products_quantity >= 1 THEN 2 END desc , priceWithTax ASC, products_name

[TEP STOP]