sql语句问题,可以这样写吗?

KcSoft 2006-12-25 11:29:16
update table1 set name=case when a.yin>0 then 1 else a.yin
where id=3 select sum(yin) as yin from table1 a where id=3
...全文
136 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2006-12-25
  • 打赏
  • 举报
回复
改一下就可以了
update table1
set name=case when (select sum(yin) from table1 a where id=table1.id)>0 then 1
else select sum(yin) from table1 a where id=table1.id) end
where id=3
QQMagicer 2006-12-25
  • 打赏
  • 举报
回复
也可以这么写
update table1
set name=case when sum(yin)>0 then 1 else sum(yin)
where id=3
QQMagicer 2006-12-25
  • 打赏
  • 举报
回复
update table1
set name=case when a.yin>0 then 1 else a.yin
from table1,(select sum(yin) as yin from table1 where id=3) as a
where id=3
冷箫轻笛 2006-12-25
  • 打赏
  • 举报
回复
我看是两句
update table1 set name=case when a.yin>0 then 1 else a.yin
where id=3

select sum(yin) as yin from table1 a where id=3
leo_lesley 2006-12-25
  • 打赏
  • 举报
回复
你写的是几句话
leo_lesley 2006-12-25
  • 打赏
  • 举报
回复
乱写的
cwlcwr 2006-12-25
  • 打赏
  • 举报
回复
GZ

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧