--测试示例
select 用户名
,用户钢瓶总数=sum(cast(left(备注,patindex('%[^0-9]%',备注+'+')-1) as int))
,已经出库的钢瓶数=sum(len(stuff(备注,1,patindex('%[^0-9]%',备注+'+')-1,'')))
from(
select 用户名=1,备注='5+++'
union all select 1,'6+'
union all select 2,'6+++++'
union all select 3,'7'
)a group by 用户名
select 用户名
,用户钢瓶总数=sum(cast(left(备注,patindex('%[^0-9]%',备注+'+')-1) as int))
,已经出库的钢瓶数=sum(len(stuff(备注,1,patindex('%[^0-9]%',备注+'+')-1,'')))
from 表
group by 用户名
--按用户名分组统计
select 用户名
,用户钢瓶总数=sum(cast(left(备注,patindex('%[^0-9]%',备注)-1) as int))
,已经出库的钢瓶数=sum(len(stuff(备注,1,patindex('%[^0-9]%',备注)-1,'')))
from 表
group by 用户名