Posted - 11/29/2024 : 11:12:06
I'm trying to do multiple levels of conditions for sorting by using a subquery, and I think there is something that is not correct in the subquery. What this is attempting to do is to take the top 8 pNumSales, then list anything where the checkbox in pCustom8 is checked, and then the rest of the pNumSales. The purpose is to be able to give a bump to selected items (new items, or other featured items) where there isnt enough sales data:
$customsortby='CASE WHEN pNumSales IN (SELECT pNumSales FROM products ORDER BY pNumSales DESC LIMIT 8) THEN 0 WHEN pCustom8 = TRUE THEN 1 ELSE 2 END, pNumSales DESC, pPopularity DESC'
The access to the SQL query via the new $customsortby works well for other advanced examples. This one puts anything with the pCustom8 checked at the very top, then it takes the new items within the last 90 days, and then puts them in order of pNumSales. This one works perfectly!
$customsortby='CASE WHEN pCustom8 = TRUE THEN 0 WHEN pDateAdded >= CURRENT_DATE - INTERVAL 90 DAY THEN 1 ELSE 2 END, pDateAdded DESC, pNumSales DESC'
In the first example, where I am trying to use a subquery, I think it is something in this part: WHEN pNumSales IN (SELECT pNumSales FROM products ORDER BY pNumSales DESC LIMIT 8) Anyone who has more knowledge of how this query is generated might be able to help. Thanks!
|