如何在postgresql上加总行

时间:2018-03-15 17:29:27

标签: postgresql-9.1

<html>
    <head>
        <!-- App Favicon -->
        <link rel="shortcut icon" href="%PUBLIC_URL%/assets/images/favicon.ico">

        <!-- Switchery css -->
        <link href="%PUBLIC_URL%/assets/plugins/switchery/switchery.min.css" rel="stylesheet" />

        <!-- Bootstrap CSS -->
        <link href="%PUBLIC_URL%/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <!-- Modernizr js -->
        <script src="%PUBLIC_URL%/assets/js/modernizr.min.js"></script>

    </head>

    <body class="fixed-left">
      <noscript>
        You need to enable JavaScript to run this app.
      </noscript>
      <div id="root"></div>
      <script>
          var resizefunc = [];
      </script>

      <!-- jQuery  -->
      <script src="%PUBLIC_URL%/assets/js/jquery.min.js"></script>
    </body>
</html>

以上是我的表格样本 我只想添加一个总列

ID  pp1 pp2 pp3 pp4 pp5 Total
A   100 33  45  67  88
B   20  34  46  68  44
C   59  35  47  69  45
D   23  36  48  70  46
E   23  37  49  71  47
F   11  38  50  72  48
G   45  39  51  73  49

我尝试了这段代码但没有结果

ID  pp1 pp2 pp3 pp4 pp5 Total
A   100 33  45  67  88  333
B   20  34  46  68  44  212
C   59  35  47  69  45  255
D   23  36  48  70  46  223
E   23  37  49  71  47  227
F   11  38  50  72  48  219
G   45  39  51  73  49  257

.....谢谢

1 个答案:

答案 0 :(得分:0)

删除Sum它是一个聚合函数

SELECT "ID", "pp1", "pp2", "pp3", "pp4", "pp5",("pp1"+"pp2"+"pp3"+"pp4"+"pp5") as Total
FROM TableName