Query Error 3029: Expression #2 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query
Query: SELECT DISTINCT p.*,p.id,(p.count > 0 || p.count IS NULL) AS in_stock
FROM shop_product p
LEFT JOIN shop_product_stocks sps1
ON p.id=sps1.product_id
WHERE p.status = 1
AND 0
AND sps1.stock_id=2
ORDER BY in_stock DESC,sum(sps1.count) DESC
LIMIT 500