我理解您的问题意味着您的card
表当前有一个名为的列casting cost
,其中包含一组颜色,例如'red,green'
or'blue,orange,yellow'
并且您正在寻找一个查询,该查询产生布尔列,指示每种可能的颜色是否在casting cost
?
如果是这样,MySQL的FIND_IN_SET()
功能应该给你你所追求的:
SELECT *,
FIND_IN_SET('red', `casting cost`) > 0 AS red,
FIND_IN_SET('blue', `casting cost`) > 0 AS blue,
FIND_IN_SET('green', `casting cost`) > 0 AS green,
FIND_IN_SET('orange', `casting cost`) > 0 AS orange,
FIND_IN_SET('yellow', `casting cost`) > 0 AS yellow
FROM card
如果要永久更改表以包含此类列:
ALTER TABLE card
ADD COLUMN red BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN blue BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN green BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN orange BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN yellow BOOLEAN NOT NULL DEFAULT FALSE
UPDATE card SET
red = FIND_IN_SET('red', `casting cost`) > 0,
blue = FIND_IN_SET('blue', `casting cost`) > 0,
green = FIND_IN_SET('green', `casting cost`) > 0,
orange = FIND_IN_SET('orange', `casting cost`) > 0,
yellow = FIND_IN_SET('yellow', `casting cost`) > 0