sqlite结合选择搜索结果

时间:2012-02-06 02:26:46

标签: sqlite

好的,所以这是我的两张桌子。

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 == 1vstr,而不是|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

结果表看起来像这样,其中列rankcustom_properties.name来自|id | game_id | set_id | name | image | range | rank | +---+---------+--------+------+-------+-------+------+ |a | asdf | fdsaf | loler| blah | 12 | face | +---+---------+--------+------+-------+-------+------+

{{1}}

2 个答案:

答案 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)

实际上不可能这样做。