目前尚不清楚,如果「數」是一個以前的查詢或簡單場的聚合函數,但是,如果它是一個簡單的領域,如以下數據:
CREATE TABLE table1(
c1 integer,
c2 integer,
c3 integer,
c4 integer,
c5 integer,
count integer
);
INSERT INTO table1 VALUES (1,2,3,4,5,3);
INSERT INTO table1 VALUES (2,3,4,5,6,2);
INSERT INTO table1 VALUES (2,3,5,6,7,2);
CREATE TABLE table2(
c1 integer,
c2 integer,
c3 integer,
c4 integer,
c5 integer,
count integer
);
INSERT INTO table2 VALUES (1,3,4,5,6,3);
INSERT INTO table2 VALUES (1,2,3,4,5,2);
你可以通過這種方式獲得您的數據:
SELECT c1, c1,c2, c3, c4,c5,SUM(count) AS count
FROM (
SELECT * FROM table1
UNION ALL
SELECT * FROM table2) AS foo
GROUP BY c1, c2, c3, c4, c5
ORDER BY c1, c2, c3, c4, c5
我希望這可以幫助你
「的問題,要求代碼必須表現出對問題的理解最小正在解決。包括嘗試的解決方案,爲什麼他們不工作,以及預期的結果「 – zero323
在sql中,count()是一個聚合函數的名稱,最好不要用它作爲列名 – wildplasser