我有两个表格(inputs和categories):
CREATE TABLE categories (
iId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
sName TEXT NOT NULL,
iParent INTEGER,
FOREIGN KEY (iParent) REFERENCES categories(iId)
);
CREATE TABLE inputs (
iId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
iCategory INTEGER,
dValue DOUBLE NOT NULL,
FOREIGN KEY (iCategory) REFERENCES categories(iId)
);
我需要从输入表(inputs table)中为每个类别(category)获取总和(dValue列)。即使总和为零也要返回。
如果可能的话,最好能够获得每个父类别(parent category)的总和(当categories.iId = categories.iParent
时,将子类别的结果汇总到父类别中)
有人能帮我吗?我感激任何帮助!谢谢!