I have a table containing color options for a product. Color options include the hexadecimal color code that is used to create the user interface (HTML).
I would like to sort the lines so that the colors in the user interface look like a rainbow, and not the current order, which is sorted based on the color name (not very useful).
This is what my request looks like. I get decimal RGB values from hexadecimal code. I just don’t know how to order it.
I studied color difference algorithms. They seem more useful for comparing the similarity of two colors, rather than sorting.
I am using MySQL.
select a.*, (a.c_r + a.c_g + a.c_b) color_sum
from (
select co.customization_option_id,
co.designer_image_url,
concat(co.name, " (",cog.name, ")") name,
co.customization_option_group_id gr,
designer_hex_color,
conv(substr(designer_hex_color, 1, 2), 16, 10) c_r,
conv(substr(designer_hex_color, 3, 2), 16, 10) c_g,
conv(substr(designer_hex_color, 5, 2), 16, 10) c_b
from customization_options co
left join customization_option_groups cog
on cog.id = co.customization_option_group_id
where co.customization_id = 155
and co.customization_option_group_id
in (1,2,3,4)) a
order by ????