我瞭解您的問題,意思是您的card
表格當前有一個名爲casting cost
的列,其中包含一組顏色,例如, 'red,green'
或'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
你能告訴我們一些你的數據看起來像什麼樣的例子,以及期望的輸出是什麼? – Daan
我不清楚......我們需要更多的信息,你能更具體嗎? – jcho360