将查询结果的小数位数设置为4



以下是我为计算特定产品的故障率而构建的代码。

ASU QTY-是保修期内的总产品

Dispatch QTY-是产品具有的总故障

Fiscal_Week-是产品失败的一周吗

如果我需要得到Failure Rate-表示为MDR

我需要分配调度QTY/ ASU QTY

在代码中,我使用了以下

cast(isnull([Dispatch QTY],0) as float)/Cast(isnull([ASU QTY],0) as float) * 100 as 'MDR'

我需要以下输出

  1. 仅将小数位数设置为5
  2. 添加%

提取故障率的完整代码

select a.FISCAL_WEEK
,isnull([ASU QTY],0) as 'ASU QTY'
,isnull([Dispatch QTY],0) as 'Dispatch QTY' 
,cast(isnull([Dispatch QTY],0) as float)/Cast(isnull([ASU QTY],0) as float) * 100  as 'MDR'

from ASU a left Join dispatch b
on
a.FISCAL_WEEK = b.FISCAL_WEEK
order by a.FISCAL_WEEK`

CAST将结果传递给decimal(20,5),然后传递给string

cast (
cast (
cast(isnull([Dispatch QTY],0) as float)
/ cast(isnull([ASU QTY],0) as float) * 100 
as decimal(20,5) )
as varchar(20) ) + '%'  as 'MDR'

最新更新