求一个记录集的SQL写法,很简单,只是我太笨!

handyworkroom 2003-08-20 08:28:23
一张表有一个money字段,和一个isdebit(bit型)字段,我想对money求和,但如果isdebit是0,就加这个数负值;为1的话,就加些数的本身值
...全文
27 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
w_jie 2003-08-20
  • 打赏
  • 举报
回复
用case

大概这样
select sum(case when sdebit=1 then [money] else -[money] end) from 表
pengdali 2003-08-20
  • 打赏
  • 举报
回复
select sum(case when isdebit=0 then -[money字段] else money字段 end) 和 from 表

34,590

社区成员

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

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