gpt4 book ai didi

sql-server - 将颜色名称转换为 RGB

转载 作者:行者123 更新时间:2023-12-04 01:53:45 31 4
gpt4 key购买 nike

我有一个记录表,每个记录表存储一个颜色名称。例如:

Product    |  Colour
-------------------
Product A | Blue
Product B | Black

我添加了 3 个新列:R、G 和 B。如何使用单个 SQL 查询将颜色转换为 RGB 值?

最佳答案

;with Colours(Name, R, G, B) as
(
select 'White', 255, 255, 255 union all
select 'Silver', 192, 192, 192 union all
select 'Gray', 128, 128, 128 union all
select 'Black', 0 , 0 , 0 union all
select 'Red', 255, 0 , 0 union all
select 'Maroon', 128, 0 , 0 union all
select 'Yellow', 255, 255, 0 union all
select 'Olive', 128, 128, 0 union all
select 'Lime', 0 , 255, 0 union all
select 'Green', 0 , 128, 0 union all
select 'Aqua', 0 , 255, 255 union all
select 'Teal', 0 , 128, 128 union all
select 'Blue', 0 , 0 , 255 union all
select 'Navy', 0 , 0 , 128 union all
select 'Fuchsia', 255, 0 , 255 union all
select 'Purple', 128, 0 , 128
)
update P set
R = C.R,
G = C.G,
B = C.B
from products as P
inner join Colours as C
on P.Colour = C.Name

关于sql-server - 将颜色名称转换为 RGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5742701/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com