sql语句 最后一行增加合计 50
selectshuliangas数量,shoujiaas售价fromdingdanselect'合计金额',sum(shuliang*shoujia)fromdingda...
select shuliang as 数量 ,shoujia as 售价 from dingdan select '合计金额 ',sum(shuliang * shoujia)
from dingdan
怎么才能把合计 加到最后一行啊 展开
from dingdan
怎么才能把合计 加到最后一行啊 展开
3个回答
展开全部
select shuliang as 数量 ,shoujia as 售价 from dingdan
UNION ALL
select '合计金额 ' as 数量 ,sum(shuliang * shoujia) as 售价
from dingdan
UNION ALL
select '合计金额 ' as 数量 ,sum(shuliang * shoujia) as 售价
from dingdan
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-08-29
展开全部
select shuliang as 数量 ,shoujia as 售价 from dingdan
union
select '合计金额 ' as 数量,sum(shuliang * shoujia) as 售价
from dingdan
union
select '合计金额 ' as 数量,sum(shuliang * shoujia) as 售价
from dingdan
更多追问追答
追问
消息 245,级别 16,状态 1,第 1 行
在将 varchar 值 '合计金额 ' 转换成数据类型 int 时失败。
追答
select cast(shuliang as varchar(2) ) as 数量 ,shoujia as 售价 from dingdan
union
select '合计金额 ' as 数量,sum(shuliang * shoujia) as 售价
from dingdan
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
drop table temp;
create table temp(
num varchar2(10),
price number(10,2)
);
insert into temp values(3,11145);
insert into temp values(4,245);
insert into temp values(3,83);
insert into temp values(1,49);
insert into temp values(30,145);
commit;
select t.num,t.PRICE from temp t
union
select '合计金额',sum(x.price) from temp x
输出结果
1 1 49
2 3 83
3 3 11145
4 30 145
5 4 245
6 合计金额 11667
用UNION时,t.num(数量)和 ‘合计金额’ 的数据类型必须相同
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询