为 Query 的结果设置小数位数为 4
Set decimal places for 4 for results from Query
以下是我为计算特定产品的故障率而构建的代码。
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'
我需要输出如下
- 仅将小数位数设置为 5
- 增加 %
提取失败率的完整代码
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'
以下是我为计算特定产品的故障率而构建的代码。
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'
我需要输出如下
- 仅将小数位数设置为 5
- 增加 %
提取失败率的完整代码
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'