求助,关于SQL的

starj1 2005-10-18 05:59:14
表A:
code as int32 '编码
merchandise as int32 '商品编码
depot as int32 '仓库编码
quantity as int32 '库存数量

表B:
code as int32 '商品编码
merchandise as string '商品名称
merchandisetype as code '商品类别
unit as string '单位
lowstock as int32 '报警库存量
safestock as int32 '安全库存量

表C:
code as int32 '商品类别编码
merchandisetype as string '商品类别名称
——————————————————————————
商品在不同的仓库中都可能存货,现在想要知道这样的结果:
在某种商品的总库存数量低于报警库存量时,需要知道要补充多少商品才能达到安全库存。
在查询结果中必须列出:
商品类别、商品名称、商品单位、目前总库存量、需要补充数量
select和where太不好写了,高手赶紧帮我,谢谢谢谢^_^
...全文
121 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
starj1 2005-11-01
  • 打赏
  • 举报
回复
在一次查询里好象出不来...只能通过临时表来实现了..........
一直在攀登 2005-10-30
  • 打赏
  • 举报
回复
自己寫個存出過程吧
lxzm1001 2005-10-30
  • 打赏
  • 举报
回复
create table A
(code int,merchandise int,depot int,quantity int)

create table B
(code int,merchandise varchar(30),merchandisetype varchar(10),unit varchar(50),lowstock int,safesstock int)

create table C
(code int,merchandisetype varchar(20))
starj1 2005-10-18
  • 打赏
  • 举报
回复
哪位帮我构建整个SQL下,三天结贴,先回去了,谢谢
starj1 2005-10-18
  • 打赏
  • 举报
回复
hamadou(闵峰) :
能不能麻烦您帮我把整个SQL句构建下,我还是有点弄不明白
starj1 2005-10-18
  • 打赏
  • 举报
回复
你是说把
((select sum(quantity) from a where a.merchandise=x.code) -x.lowstock) as qty2 < lowstock
这句先加在where中到子句?
hamadou 2005-10-18
  • 打赏
  • 举报
回复
用case when 也可以。
hamadou 2005-10-18
  • 打赏
  • 举报
回复
哦,那就要先判断((select sum(quantity) from a where a.merchandise=x.code) -x.lowstock)as qty2是否小于0了。
starj1 2005-10-18
  • 打赏
  • 举报
回复
还一个,SQL要OLEDb能支持的,我没装SQL Server:(
starj1 2005-10-18
  • 打赏
  • 举报
回复
hamadou(闵峰) :
这个SQL没看出来在哪限制只统计库存量低于报警库存量啊?
select子句倒是很复杂^_^
hamadou 2005-10-18
  • 打赏
  • 举报
回复
select x.code,x.merchandise,x.unit,y.merchandisetype,x.merchandisetype,
(select sum(quantity) from a where a.merchandise=x.code) as qty1,
((select sum(quantity) from a where a.merchandise=x.code) -x.lowstock)as qty2
from b x,c y
where x.merchandisetype=y.code

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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