I have several tables on a PostgreSQL database that look more or less like that:
gid col2 col1 col3
6 15 45 77
1 15 45 57
2 14 0.2 42
3 12 6 37
4 9 85 27
5 5 1 15
For each table, numbers and columns' names change (I created them in a loop in python).
I would like to have back another column called sum for each table with the sum of each calumn except for the gid. The goal is having something like that:
gid col2 col1 col3 sum
6 15 45 77 137
1 15 45 57 117
2 14 0.2 42 56.2
3 12 6 37 55
4 9 85 27 121
5 5 1 15 21
I cannot use column name: the only one with no changes is gid
.
Some idea to make it with python
(pandas
, numpy
) or psql
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…