那我要写寿命小于10%的模具数量的代码应该怎么写
时间: 2024-02-18 16:02:51 浏览: 107
如果您需要查询寿命小于10%的模具数量的代码,可以在原来的代码基础上稍作修改,如下所示:
```
with a01 as (
select distinct
isname as '产业',
case
when isname in ('冰箱', '冷柜') then '制冷'
when isname = '商空' then '智慧楼宇'
else isname
end as industry,
moldcode as mould_code,
createtime
from dwd_tm_moldscrap_hmzy
where del_flag = '0'
and isname is not null
and substring(createtime,1,7) = substring(now(),1,7)
), b01 as (
select a.*, b.day_compri, b.model_deslife,
case
when cast(cast(b.day_compri as decimal(8,1))/cast(b.model_deslife as decimal(8,1)) as float) < 0.1 then '寿命小于10%'
when cast(cast(b.day_compri as decimal(8,1))/cast(b.model_deslife as decimal(8,1)) as float) > 1 then '寿命超100%'
else '未超100%'
end as bj
from a01 a
left join dwd_model_basic_information_all b
on a.mould_code = b.model_code
), c01 as (
select industry, count(distinct mould_code) as count
from b01
where bj = '寿命小于10%'
group by industry
union all
select '全产线' as industry, count(distinct mould_code) as count
from b01
where bj = '寿命小于10%'
)
select industry, count from c01;
```
这里的修改是在b01子查询中增加了一个判断,如果计算出的寿命比例小于0.1,就标记为寿命小于10%,并在最后的聚合操作中统计每个产业和全产线中寿命小于10%的模具数量。
阅读全文