select g.设备类型,sum(g.数量) 数量 from
(select
case when dv.name in (
'动力机械'
,'辅助船舶'
,'基础施工机械及辅助设备'
,'加工制造设备'
,'其他机械设备'
,'起重及垂直运输机械'
,'桥梁专用施工设备'
,'水平运输机械'
,'铁路专用施工设备'
,'土、石方工程机械'
,'筑养路设备') then dv.name
else '其他' end 设备类型,
count(1) 数量
from dm_device as dv , dm_device_base_info as b
left join (select entryInfos.* from dm_device_entry entryInfos
join (select entryInfo.device_base_id, max(entryInfo.create_time) createTime
from dm_device_entry entryInfo where entryInfo.delete_flag = 1
group by entryInfo.device_base_id ) deviceEntryInfo
on entryInfos.device_base_id = deviceEntryInfo.device_base_id
and entryInfos.create_time = deviceEntryInfo.createTime) entry ON entry.device_base_id = b.id
join dm_device as de ON dv.id = de.parent_id
join dm_device as a on de.id = a.parent_id
where b.delete_flag = 1
and b.audit_state= 4
and entry.audit_state in (1, 2, 3, 4, 5)
and b.device_class =1
and dv.id = b.device_id
and a.id = b.device_id
and b.device_status=2
GROUP BY dv.name ) as g
GROUP BY g.设备类型
别名和空格也加了,就是不行