我有一个包含三个表的数据库:
表格1
CREATE TABLE "A" ( "id" INTEGER PRIMARY KEY NOT NULL
,"cat_id" INTEGER NOT NULL
,"date" DATETIME NOT NULL
,"amount" VARCHAR NOT NULL DEFAULT (0.0)
,"notes" VARCHAR)
表 2:
CREATE TABLE "B" ( "id" INTEGER PRIMARY KEY NOT NULL
,"cat_id" INTEGER NOT NULL
,"date" DATETIME NOT NULL
,"amount" VARCHAR NOT NULL DEFAULT (0.0)
,"notes" VARCHAR)
表3:
CREATE TABLE "c" ( "id" INTEGER PRIMARY KEY NOT NULL
,"parent_id" INTEGER NOT NULL DEFAULT (0)
,"name" VARCHAR NOT NULL
,"position" INTEGER NOT NULL
,"importance" INTEGER NOT NULL DEFAULT (0)
,"transaction_type" VARCHAR NOT NULL DEFAULT expenses
,"icon" VARCHAR NOT NULL DEFAULT default
,"budget" INTEGER NOT NULL DEFAULT 0
,"status" INTEGER NOT NULL DEFAULT 1)
我使用此语句从表中进行选择,A
并且B
:
SELECT * FROM A
UNION ALL
SELECT * FROM B
ORDER BY date
我想将此 select 语句的结果与第三个表C
连接起来:
RIGHT JOIN C on A.cat_id = C.id
RIGHT JOIN C on B.cat_id = C.id
我怎样才能做到这一点?!