If the empty fields have NULL value, you can use
SELECT * FROM sometable ORDER BY ISNULL(price_1) + ISNULL(price_2) + ISNULL(price_3) DESC;
But a more sensible solution would be:
- You have one table, which contains the products
- You have another
table, which contains the product’s ID, the price and a value which
indicates which website provided that price.
Benefits:
- You only have to
COUNT(*)
the entries of a product in the second table to find out on how many it is listed - You can change the number of websites any time without changing a table
2
solved Mysql sort BY number of filled columns [closed]