Для MySQL 8.0 и более поздних версий существуют оконные функции для создания совокупной цены для разрешенных цветов:
select count(*) -- counts the number of items
from
(
select sum(p1.purchasePrice) over (order by p1.purchasePrice asc) as c_price -- Our cumulative price
from product p1
where colour in ('white', 'red') -- limit the colours
) x2
where x2.c_price <= 20 -- where the cumulative is less than the budget
РЕДАКТИРОВАТЬ: кажется, вы ищете, сколько из каждого предмета вы можете купить, а не сколько из списка:
select colour, purchasePrice,
floor(20/purchasePrice) as qty_for_20 -- floor rounds the number down
from products
where colour in ('white', 'red')