好的,所以这是我的两张桌子。
CREATE TABLE [cards] (
[id] TEXT PRIMARY KEY,
[game_id] TEXT NOT NULL,
[set_id] TEXT CONSTRAINT [id_set_id] REFERENCES [sets]([id]) ON DELETE CASCADE ON UPDATE CASCADE MATCH SIMPLE NOT DEFERRABLE INITIALLY IMMEDIATE,
[name] TEXT NOT NULL,
[image] TEXT NOT NULL);
CREATE TABLE [custom_properties] (
[id] TEXT PRIMARY KEY,
[card_id] TEXT CONSTRAINT [id_card_id] REFERENCES [cards]([id]) ON DELETE CASCADE ON UPDATE CASCADE MATCH SIMPLE NOT DEFERRABLE INITIALLY IMMEDIATE,
[game_id] TEXT CONSTRAINT [id_game_id4] REFERENCES [games]([id]) ON DELETE CASCADE ON UPDATE CASCADE MATCH SIMPLE NOT DEFERRABLE INITIALLY IMMEDIATE,
[name] TEXT NOT NULL,
[type] INTEGER NOT NULL,
[vint] INTEGER,
[vstr] TEXT);
我想要做的是搜索从cards
行抓取所有数据,然后添加名称为(where custom_properties.card_id == cards.id).name
的列。
那么我希望vint
type == 1
,vstr
,而不是|id | game_id | set_id | name | image|
+---+---------+--------+------+------+
| a | asdf | fdsaf |loler | blah |
+------------------------------------+
。
所以,这是一个示例数据集
卡
| id | card_id | game_id | name | type | vint | vstr |
+----+---------+---------+------+------+------+------+
| f | a | asdf | range| 1 | 12 | |
| b | a | asdf | rank | 0 | | face |
+----+---------+---------+------+------+------+------+
custom_properties
range
结果表看起来像这样,其中列rank
和custom_properties.name
来自|id | game_id | set_id | name | image | range | rank |
+---+---------+--------+------+-------+-------+------+
|a | asdf | fdsaf | loler| blah | 12 | face |
+---+---------+--------+------+-------+-------+------+
{{1}}
答案 0 :(得分:0)
试试这个:
SELECT Cards.id,
Cards.game_id,
Cards.set_id,
Cards.name,
Cards.id,
Cards.image,
CASE
WHEN Custom_Properties.type = 1 THEN
Custom_Properties.vint
ELSE
Custom_Properties.vstr
END as Range
Custom_Properties.vstr as rank
FROM Cards INNER JOIN Custom_Properties
ON Cards.id = Custom_Properties.card_ID
WHERE Cards.Name = 'loller'
答案 1 :(得分:0)
实际上不可能这样做。