惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - billqi(岁月如水)

解除webservice上下传文件大小限制 [转贴]请不要做浮躁的人! BBS 水木清华站 msmq两个网域之间消息传输与接收测试总结 msmq消息队列使用及测试总结 PDA 应用领域 GPS的十大绝技 GSM - billqi(岁月如水) - 博客园 深圳面试提醒(特别针对女生) CRM功能架构 VMI的理念与应用 台湾供货商管理库存(VMI)导入指引 SMART原则与自我激励 msmq 之触发器 微软架构师网站 - billqi(岁月如水) 绩效考核的KPI及SMART原则 微软.net framework工具集帮助 2年前的建议书 Server群集部署? 新的天地
sql查询语句问题- sum求和的值作为查询条件
billqi(岁月如水) · 2005-02-18 · via 博客园 - billqi(岁月如水)
   

在物流系统开发过程中碰到这样一个问题,项目组的人讨论了很久用了这样的解决方法,

肯定还有地方需要优化,我先把我们的思路写出来,哪位朋友比较感兴趣,帮忙优化一下。

某储位档是已经按照优先级别排序的集合,字段有[储位代码(locationcode)储位产品存放数量(pilenum),优先级(level)]

现在要从该表中按照排好的顺序取出150个产品。如何最简单实现?

创建测试资料文件某储位档(test1)

the following is our sql script:

select identity(int,1,1) as rID,* into #test from test1

select * from #test

if not exists(select * from #test a where (select sum(pilenum) from #test where rID <= a.rID) <90)

           begin

                     select top 1 * from #test

           end

else

           begin

                     select * from #test a where (select sum(pilenum) from #test where rID <= a.rID) < 90

                     union (select * from #test where rID = (select max(rID) from #test a where (select sum(pilenum) from #test where rID <= a.rID) < 90)+1)

           end

drop table #test

executed result: 
    

rID locationcode  pilenum level 1 T-E03-2    34 1 2 T-E03-3    50 1 3 T-E03-6    50 1 4 T-E03-7    12 1 5 T-E03-8    80 2 6 T-E04-5    30 3 7 T-E04-7    50 2
rIDlocationcode pilenumlevel1T-E03-2   3412T-E03-3   5013T-E03-6   501