select * from locations

order by

(case when product1='Y' then 1 else 0 end +

case when product2='Y' then 1 else 0 end +

case when product3='Y' then 1 else 0 end +

case when product4='Y' then 1 else 0 end +

case when product5='Y' then 1 else 0 end +

case when product6='Y' then 1 else 0 end +

case when product7='Y' then 1 else 0 end +

case when product8='Y' then 1 else 0 end +

case when product9='Y' then 1 else 0 end +

case when product10 = 'Y' then 1 else 0 end

)

order by

(case when product1='Y' then 1 else 0 end +

case when product2='Y' then 1 else 0 end +

case when product3='Y' then 1 else 0 end +

case when product4='Y' then 1 else 0 end +

case when product5='Y' then 1 else 0 end +

case when product6='Y' then 1 else 0 end +

case when product7='Y' then 1 else 0 end +

case when product8='Y' then 1 else 0 end +

case when product9='Y' then 1 else 0 end +

case when product10 = 'Y' then 1 else 0 end

)