0

I have two tables in a sqlite database like:

CREATE TABLE list (
    list_id INTEGER NOT NULL PRIMARY KEY,
    title TEXT NOT NULL
);

CREATE TABLE item (
    item_id INTEGER NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    completed INTEGER NOT NULL,
    list_id INTEGER NOT NULL REFERENCES list (list_id)
);

I want to perform a query on the list table that returns the id, title and creates a variable completed that is true or 1 if all of the item rows that reference it are completed otherwise false or 0.

I am quite new to sql (so not sure if this is even possible) but this is just a bit beyond me at the moment. Any help or pointers in the right direction would be much appreciated.

4

1 回答 1

1

假设completeditem桌子上是 1 或 0。

SELECT  L.LIST_ID
        ,L.TITLE
        ,MAX(I.COMPLETED)
FROM    LIST L
LEFT OUTER JOIN
        ITEM I
ON      I.LIST_ID = L.LIST_ID
GROUP BY
        L.LIST_ID
        ,L.TITLE
于 2013-05-13T20:46:58.977 回答