select a,b,c,d from myTabel查出10条记录希望增加一行记录在最后成为第11行计算a,c的合计

解决方案 »

  1.   

    假设B、D为数字型 
    select a,b,c,d from myTabel
    union all
    select sum(a),0,sum(c),0 from (
    select a,b,c,d from myTabel) a
      

  2.   

    select a,b,c,d,sum(a+c) as e from myTabel group by id
      

  3.   

    对不起!!!!!!我没说清我意思是最后一行  显示出  a列和   c列  的合计   而不是a+c
      

  4.   

    没明白...
    难道你的意思是当你要统计A+B的时候就显示出A+B?,当你要统计A+C的时候就显示A+C?
      

  5.   

    酱说a     b     c     d
    10    bob   4     man
    13    peter 51    man
    15    neo   12    woman
    38    null  67    null    (分别合计A列、C列)
      

  6.   

    select a,b,c,d from myTabel
    union all
    select sum(a),null,sum(c),null from (
    select a,b,c,d from myTabel) a
      

  7.   

    select a,b,c,d from myTabel
    union all
    select sum(a) a ,null b,sum(c) c,null c 
    from (
         select a,b,c,d from myTabel
    ) a
      

  8.   

    select a,b,c,d from myTabel
    union all
    select sum(a) a ,null b,sum(c) c,null d 
    from (
         select a,b,c,d from myTabel
    ) a
      

  9.   

    select a,b,c,d
    from table1
    union all
    select sum(a),null,sum(c),null
    from table1
      

  10.   

    mysql> select * from table1;
    +------+-------+------+-------+
    | a    | b     | c    | d     |
    +------+-------+------+-------+
    |   10 | bob   |    4 | man   |
    |   13 | peter |   51 | man   |
    |   15 | neo   |   12 | woman |
    +------+-------+------+-------+
    3 rows in set (0.00 sec)mysql>
    mysql> select a,b,c,d
        -> from table1
        -> union all
        -> select sum(a),null,sum(c),null
        -> from table1
        -> ;
    +------+-------+------+-------+
    | a    | b     | c    | d     |
    +------+-------+------+-------+
    |   10 | bob   |    4 | man   |
    |   13 | peter |   51 | man   |
    |   15 | neo   |   12 | woman |
    |   38 | NULL  |   67 | NULL  |
    +------+-------+------+-------+
    4 rows in set (0.00 sec)mysql>