0317.rar
如果不想用值1计算,sql 如下是oracel的,,sql serve 类似一样的用ROW_NUMBER() OVER判断就行了。。你改成你的表名称就行。。
select
列1,
列11,
值1,
合计1,
case when ROW_NUMBER() OVER(PARTITION BY 列1 ORDER BY 列1)=1 then 合计1
else 0 end as 判断后合计1
from (
select 'A' as 列1,'A1' as 列11,23 as 值1,72 as 合计1 from dual union all
select 'A' as 列1,'A2' as 列11,23 as 值1,72 as 合计1 from dual union all
select 'A' as 列1,'A3' as 列11,23 as 值1,72 as 合计1 from dual union all
select 'B' as 列1,'B1' as 列11,21 as 值1,21 as 合计1 from dual union all
select 'C' as 列1,'C1' as 列11,15 as 值1,35 as 合计1 from dual union all
select 'C' as 列1,'C2' as 列11,20 as 值1,35 as 合计1 from dual
) t