我希望产品ABC移到列表的顶部,而其余的移到下面。
和
注:是的,尺寸可以增加,但我只想检查这些尺寸(S、M、L)
order by count(case when stock <> 0 then 1 end)
where size in ('S','M','L')
select product_id, product_name
from product_attributes
where size in ('S','M','L')
group by product_id,product_name
order by count(case when stock <> 0 then 1 end) desc
Demo Link MySQL 8.0 | db<>fiddle