我在SQLite
CREATE TABLE "INVENTORY" {
"product" VARCHAR NOT NULL,
"version" VARCHAR NOT NULL,
"quantity" INTEGER,
//etc
}
和一些记录就像
"product" - "01" - 1000
"product" - "01" - 1000
"product" - "02" - 4000
"product" - "02" - 1000
"product" - "03" - 3000
我尝试进行查询,以便获得每种产品和版本的所有金额。在上面的示例中,查询将返回
"product" - "01" - 2000
"product" - "02" - 5000
"product" - "03" - 3000
我尝试了这个返回ambiguous column name: product
SELECT product , version, SUM(quantity) AS total
from INVENTORY
INNER JOIN INVENTORY
ON product AND version
GROUP BY product, version
答案 0 :(得分:2)
SELECT product, version, SUM(quantity) AS total
FROM INVENTORY
GROUP BY product, version