我有以下疑问。
insert into tbl_percount([H1Cycle],[perOffshore],[perOnsite],[perTotal])
(select [H1Cycle],Round(cast([Offshore]*100.0/(select [Offshore] from tbl_FinalLastday where [H1Cycle]='H1 Total')as float),2) as 'perOffshore',
Round(cast([Onsite]*100.0/(select [Onsite] from tbl_FinalLastday where [H1Cycle]='H1 Total')as float),2) as 'perOnsite',
Round(cast([Total]*100.0/(select [Total] from tbl_FinalLastday where [H1Cycle]='H1 Total')as float),2) as 'perTotal'
from tbl_FinalLastday where [H1Cycle]!='H1 Total')
insert into tbl_percount([H1Cycle],[perOffshore],[perOnsite],[perTotal])
(select [H1Cycle],Round(cast([Offshore]*100/(select [Total] from tbl_FinalLastday where [H1Cycle]='H1 Total')as float),2) as 'perOffshore',
Round(cast([Onsite]*100.0/(select [Total] from tbl_FinalLastday where [H1Cycle]='H1 Total')as float),2) as 'perOnsite',
Round(cast([Total]*100.0/(select [Total] from tbl_FinalLastday where [H1Cycle]='H1 Total')as float),2) as 'perTotal'
from tbl_FinalLastday where [H1Cycle]='H1 Total')
我希望输出为71.00,29.00,100.00
我怎么能得到这个?
答案 0 :(得分:0)
您需要cast
作为numeric(3,2)
,而不是float
。
尝试以下方法:
select cast(round([Offshore] * 100 / (
SELECT [Total]
FROM tbl_FinalLastday
WHERE [H1Cycle] = 'H1 Total'
), 2) AS NUMERIC(3, 2)) AS 'perOffshore'