select a,b,c,d from myTabel查出10条记录希望增加一行记录在最后成为第11行计算a,c的合计
解决方案 »
- Lost connection to MySQL server at 'reading initial communication packet', syste
- mysql 触发器 希望在A表insert之后,触发B表的insert操作
- libsqlpg.so无法加载的问题
- mysql的安装问题
- mysql5.0支持存储过程和触发器了?
- --------------------select 问题————————————————??
- 新手刚学数据库,问题请教!
- 通过dbExpress连接MYSQL或其它SQL服务器的问题
- 网络出不去国外,急求mysql的2000下和98下的odbc驱动,我最多只能给66分了。在线给分
- sql查询求助
- mysql 还需要优化??
- 帮我看看这个存储过程问题在哪里
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
难道你的意思是当你要统计A+B的时候就显示出A+B?,当你要统计A+C的时候就显示A+C?
10 bob 4 man
13 peter 51 man
15 neo 12 woman
38 null 67 null (分别合计A列、C列)
union all
select sum(a),null,sum(c),null from (
select a,b,c,d from myTabel) a
union all
select sum(a) a ,null b,sum(c) c,null c
from (
select a,b,c,d from myTabel
) a
union all
select sum(a) a ,null b,sum(c) c,null d
from (
select a,b,c,d from myTabel
) a
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 |
+------+-------+------+-------+
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>