select col1,cast(col2 as varchar(10)) ,col1+col2 as total from Tbl1 union all select null,'总计:',sum(col1+col2) from Tbl1
select col1 ,col2 ,col1+col2 as total from Tbl1 unin select '','总计',count(col1) * (select count(*) from sysobjects where tname = tb11)
select col1 ,col2 ,col1+col2 as total from Tbl1 unin select '','总计',count(col1) * (select count(*) from sysobjects where id = object_id('表名')) and xtype='u' 总计为行列相乘是这个意思吗? ^_^
是不是这样写的了。 select col1,col2,(col1+col2) as total from tbl1 union select '','总计',sum(col1)+sum(col2) from tbl1
sum()函数是统计数值用的,不是计算行数,列数的 select col1,col2,(col1+col2) as total from tbll union select null,'总计',count(col1)*count(*) from tbll
select cast(col1 as varchar(10)),cast(col2 as varchar(10)),(col1+col2) as total from table union all select '','总计',sum(col1+col2) from table
select cast(col1 as varchar(10)) as col1 ,cast(col2 as varchar(10)) as col2,(col1+col2) as total from table union all select '','总计',sum(col1+col2) from table
select convert(varchar(10),col1) as col1,convert(varchar(10),col2) as col2,(col1+col2) as total from test union select '','总计',sum(col1+col2) from test
select col1,col2,col1+col2 as total from Tbl1 union all select '','总计:',sum(col1+col2) from Tbl1嘿嘿
这次真的对了 SELECT cast(col1 AS varchar(10)) AS col1, cast(col2 AS varchar(10)) AS col2, (col1 + col2) AS total FROM test UNION ALL SELECT '', '总计', SUM(col1 + col2) FROM test
union all
select null,'总计:',sum(col1+col2) from Tbl1
unin
select '','总计',count(col1) * (select count(*) from sysobjects where tname = tb11)
unin
select '','总计',count(col1) * (select count(*) from sysobjects where id = object_id('表名')) and xtype='u'
总计为行列相乘是这个意思吗?
^_^
表Tbl1:字段 col1,col2,其中total=col1+col2 col1 col2 total
-----------------
1 4 5
1 5 6
2 3 5
总计: 16
select col1,col2,(col1+col2) as total from tbl1
union
select '','总计',sum(col1)+sum(col2) from tbl1
select col1,col2,(col1+col2) as total from tbll
union
select null,'总计',count(col1)*count(*) from tbll
union all
select '','总计',sum(col1+col2) from table
union all
select '','总计',sum(col1+col2) from table
union
select '','总计',sum(col1+col2) from test
union all
select '','总计:',sum(col1+col2) from Tbl1嘿嘿
SELECT cast(col1 AS varchar(10)) AS col1, cast(col2 AS varchar(10)) AS col2, (col1 + col2)
AS total
FROM test
UNION ALL
SELECT '', '总计', SUM(col1 + col2)
FROM test