Foxtable(狐表)用户栏目专家坐堂 → [求助]SQL语句问题,求帮助~


  共有4043人关注过本帖树形打印复制链接

主题:[求助]SQL语句问题,求帮助~

帅哥哟,离线,有人找我吗?
jiskin
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:713 积分:5196 威望:0 精华:0 注册:2012/4/13 13:10:00
[求助]SQL语句问题,求帮助~  发帖心情 Post By:2013/12/24 12:47:00 [只看该作者]

where 语句后面可以用 + - 吗?

大致如下结构:Select * from {Material_List} where StockQty + (子查询) + (子查询) + (子查询) - (子查询) <= QuantityAlert and (MaterialsClass = '外购件' or MaterialsClass = '标准件')

请问这样写是不是不正确?加上子查询就没结果了……研究半天了,还发现个问题,最后的or 一定要括弧括起来才生效居然!

实际查询语句如下:
Select * from {Material_List} where StockQty + (select sum(Quantity) from{Buy_List} where Material = {Material_List}.MaterialSpecification and Status <> '已请购') + (select sum(Quantity) from{Request_Orders} where Material = {Material_List}.MaterialSpecification and Status = '已请购') + (Select sum(Quantity) from {Purchase_Orders} where Material = {Material_List}.MaterialSpecification And IQCNumber In (Select IQCNumber from {IQC_List} where Status <> '已入库'or Status is NULL)) - (Select sum(Failure) from {Purchase_Orders} where Material = {Material_List}.MaterialSpecification And IQCNumber In (Select IQCNumber from {IQC_List} where Status <> '已入库'or Status is NULL)) <= QuantityAlert and (MaterialsClass = '外购件' or MaterialsClass = '标准件')


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/12/24 13:07:00 [只看该作者]

看不懂你的问题,这个你最好学一下sql的语句,找本书看看吧。

 


 回到顶部
帅哥哟,离线,有人找我吗?
jspta
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1731 积分:11255 威望:0 精华:0 注册:2011/12/15 22:06:00
  发帖心情 Post By:2013/12/24 14:31:00 [只看该作者]

(StockQty + (子查询) + (子查询) + (子查询) - (子查询)) <= QuantityAlert

这个可能要加括号,否则解析出现错误了
[此贴子已经被作者于2013-12-24 14:31:57编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
jiskin
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:713 积分:5196 威望:0 精华:0 注册:2012/4/13 13:10:00
  发帖心情 Post By:2013/12/24 15:10:00 [只看该作者]

以下是引用jspta在2013-12-24 14:31:00的发言:
(StockQty + (子查询) + (子查询) + (子查询) - (子查询)) <= QuantityAlert

这个可能要加括号,否则解析出现错误了
[此贴子已经被作者于2013-12-24 14:31:57编辑过]

 

刚自己研究出来了 不是因为括号的问题 是需要加上 isnull 图片点击可在新窗口打开查看 弄了大半天 郁闷


 回到顶部