这样的查询语句让我伤脑筋?只得向各位请教了,救命啊!!!!

licher 2004-04-29 03:16:22
现有这样的查询语句:
select ID, Sum(Degree)/Sum(Weight) as dw from DegreeTable
group by ID.

但是,如果Sum(Weight)为零的话,我想执行下面的语句,因为除数不允许为零。
select ID, Sum(Degree) from DegreeTable group by ID.

怎么把两个语句合成一个SQL语句啊?
...全文
68 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
licher 2004-04-29
  • 打赏
  • 举报
回复
我先试试。等下结分。
csdnwhycn 2004-04-29
  • 打赏
  • 举报
回复
同意楼上
outwindows 2004-04-29
  • 打赏
  • 举报
回复
select ID,
Sum(Degree)/( case when Sum(Weight)=0 then 1 else Sum(Weight) end ) as dw
from DegreeTable
group by ID.
zjcxc 元老 2004-04-29
  • 打赏
  • 举报
回复
select ID,case Sum(Weight) when 0 then Sum(Degree) else Sum(Degree)/Sum(Weight) end as dw from DegreeTable
group by ID

34,838

社区成员

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

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