您的结果包含三列。
标签,总和(值),总和(计数)
所以
label sum
A 12491
B 213295
C 1578105
你看到的是:
a 124 91
b 2132 95
c 15781 105
空间是什么?
查看我的经验:
digoal=# create table t1(id int, v int);
CREATE TABLE
digoal=# create table t2(id int, c int);
CREATE TABLE
digoal=# insert into t1 values (1,10);
INSERT 0 1
digoal=# insert into t1 values (1,20);
INSERT 0 1
digoal=# insert into t1 values (1,30);
INSERT 0 1
digoal=# insert into t1 values (2,10);
INSERT 0 1
digoal=# insert into t1 values (2,20);
INSERT 0 1
digoal=# insert into t1 values (2,30);
INSERT 0 1
digoal=# insert into t1 values (3,10);
INSERT 0 1
digoal=# insert into t1 values (3,20);
INSERT 0 1
digoal=# insert into t1 values (3,30);
INSERT 0 1
digoal=# insert into t2 select * from t1;
INSERT 0 9
digoal=# select t1.id,sum(v),sum(c) from t1 left join t2 on t1.id=t2.id group by t1.id;
id | sum | sum
----+-----+-----
1 | 180 | 180
2 | 180 | 180
3 | 180 | 180
(3 rows)
你可以设置fieldsep来查看。
pg93@db-172-16-3-150-> psql -A
psql (9.3.3)
Type "help" for help.
digoal=# \pset fieldsep ,
Field separator is ",".
digoal=# select t1.id,sum(v),sum(c) from t1 left join t2 on t1.id=t2.id group by t1.id;
id,sum,sum
1,180,180
2,180,180
3,180,180
(3 rows)