发布网友 发布时间:2023-06-23 14:44
共3个回答
热心网友 时间:2024-12-13 12:34
create table tab
(
id int identity(1,1) primary key,
[money] decimal,
jih int
)
go
insert into tab([money],jih) values(500,1)
insert into tab([money],jih) values(300,1)
insert into tab([money],jih) values(300,2)
insert into tab([money],jih) values(500,2)
insert into tab([money],jih) values(600,3)
insert into tab([money],jih) values(900,3)
insert into tab([money],jih) values(400,4)
insert into tab([money],jih) values(800,4)
go
select * from tab
go
select tab.id,tab.money,tabb.total,tab.money,
substring(
convert(varchar(100), round((tab.money/tabb.total),2)),1,4
)
as [avg],
tab.jih
from tab inner join
(select jih,sum([money]) total from tab group by(jih)) tabb
on tab.jih = tabb.jih
运行上面代码即可得到结果
热心网友 时间:2024-12-13 12:34
select a.id,a.money,a.jlh, a.money/b.sumMoney as pct热心网友 时间:2024-12-13 12:35
select money1/money2||'%' from