如何实现以下表

ny_nicholas 2005-03-09 07:30:50
select lh,訂單總量,庫存量,差異
from (select a.lh,訂單總量=isnull(sum(b.qototal),0),庫存量=a.qc
,差異=a.qc-isnull(sum(b.qototal),0)
,配额量=iif(庫存量>訂單總量,訂單總量,庫存量)
from QCTotal a
left join SoiTotal b on a.lh=b.lh and a.cb=b.cb
group by a.lh,a.qc) c

where 訂單總量<>0 order by lh

运行后报错,

服务器: 消息 170,级别 15,状态 1,行 4
第 4 行: '>' 附近有语法错误。

...全文
58 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dxhdxh 2005-03-09
  • 打赏
  • 举报
回复
select lh,訂單總量,庫存量,差異
from (select a.lh,訂單總量=sum(isnull(b.qototal,0)),庫存量=a.qc
,差異=a.qc-isnull(sum(b.qototal),0)
,配额量=(case isnull(庫存量,0)>isnull(訂單總量,0) then 訂單總量 else 庫存量 end)
from QCTotal a
left join SoiTotal b on a.lh=b.lh and a.cb=b.cb
group by a.lh,a.qc) c

where 訂單總量<>0 order by lh
chinaandys 2005-03-09
  • 打赏
  • 举报
回复
楼主,还有一个,这样写
isnull(sum(b.qototal),0)

变成 sum(isnull(b.qototal,0))
chinaandys 2005-03-09
  • 打赏
  • 举报
回复
好像没有用过iif函数。改一下用Case

配额量=(case 庫存量>訂單總量 then 訂單總量 else 庫存量 end)


没有用过iif,up

11,850

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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