34,593
社区成员
发帖
与我相关
我的任务
分享
update t set t.语文=t.语文+100 from (select quotename(name) as a,
sum( case course when '语文' then point else 0 end) as 语文,
sum(case course when '数学' then point else 0 end) as 数学,
sum(case course when '物理' then point else 0 end ) as 物理
from #a group by quotename(name)
having sum( case course when '语文' then point else 0 end) < sum(case course when '数学' then point else 0 end)) t
建议你提供详细的资料:
例如表的结构,表之间的关系,测试数据,相关算法及需要的结果。
这样有助于我们理解你的意思,更主要的是能尽快让你获得答案或解决问题的方法。
update t set t.语文=m.语文+100 from (select quotename(name) as a,
sum( case course when '语文' then point else 0 end) as 语文,
sum(case course when '数学' then point else 0 end) as 数学,
sum(case course when '物理' then point else 0 end ) as 物理
from #a group by quotename(name)
having sum( case course when '语文' then point else 0 end) < sum(case course when '数学' then point else 0 end)) m
表结构:
name course point
张三 语文 73
张三 数学 84
张三 物理 93
张四 语文 73
张四 数学 84
张四 物理 94
select quotename(name) as a,
sum( case course when '语文' then point else 0 end)+100 as 语文,
sum(case course when '数学' then point else 0 end) as 数学,
sum(case course when '物理' then point else 0 end ) as 物理
from #a group by quotename(name)
having sum( case course when '语文' then point else 0 end) < sum(case course when '数学' then point else 0 end)