选择UNTIL? [英] SELECT UNTIL ?

查看:104
本文介绍了选择UNTIL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我不是SQL n00b,但我不是SQL大师...


我想要计算出在伪代码中实现以下目标所需的SQL代码:

掌握记录

使用该记录中的信息,添加(宽度)到运行总计。

当运行总数超过某个值时,停止抓取记录。


这里有一段代码来演示功能要求:

---------------------------------------- ----------------------------------------


ImageID ImageWidth ImageBLOB

------------------------------------- -----

1 60%E $ Y ^ HYS ^ YHU%^ TRHT

2 60 O *& ^ G& * ^ OGBV& VB ^^ &

3 120 YE%$ CC%$ EYYEC%$ C%$

4 200%E $ Y ^ HYS ^ YHU%^ TRHT

5 60 O *& ^ G& * ^ OGBV& VB ^^&

6 120 YE%$ CC%$ EYYEC%$ C%$

------------------------------ ------------


Dim CurrentTotalWidth As Integer = 0

Dim MaxWidth As Integer = 240

Dim MaxWidthExceeded As Integer = 0


Do


如果CurrentTotalWidth MaxWidth那么

MaxWidthExceeded& = MaxWidthExceeded + 1

结束如果


SELECT [ImageID],[ImageWidth],[ImageBLOB],FROM [tblImages]


CurrentTotalWidth = CurrentTotalWidth + [ImageWidth]


循环直到MaxWidthExceeded = 5


----------- -------------------------------------------------- -------------------


我不认为我提交的代码是最有效的yaddah yaddah yaddah ,我愿意提出让事情变得有效的建议......也许是一个SELECT TOP 10 ...这样我运行一个查询而不是十个?等等


无论如何,

提前致谢,

Douglas

Hi

Im not an SQL n00b, but I''m no SQL guru...

I''d like to work out the SQL code required to achieve the following goal in pseudocode:

Grap a record
Using info from that record, add (the width) to a running total.
When the running total exceeds a certain value, stop grabbing records.

Here''s a snippet of code to demonstrate the functionality that is required:
--------------------------------------------------------------------------------

ImageID ImageWidth ImageBLOB
------------------------------------------
1 60 %E$Y^HYS^YHU%^TRHT
2 60 O*&^G&*^OGBV&VB^^&
3 120 YE%$CC%$EYYEC%$C%$
4 200 %E$Y^HYS^YHU%^TRHT
5 60 O*&^G&*^OGBV&VB^^&
6 120 YE%$CC%$EYYEC%$C%$
------------------------------------------

Dim CurrentTotalWidth As Integer = 0
Dim MaxWidth As Integer = 240
Dim MaxWidthExceeded As Integer = 0

Do

If CurrentTotalWidth MaxWidth Then
MaxWidthExceeded &= MaxWidthExceeded + 1
End If

SELECT [ImageID], [ImageWidth], [ImageBLOB], FROM [tblImages]

CurrentTotalWidth = CurrentTotalWidth + [ImageWidth]

Loop Until MaxWidthExceeded = 5

--------------------------------------------------------------------------------

I don''t assume that the code I have submitted is the most efficient yaddah yaddah yaddah, I''m open to suggestions to make things efficient... maybe a SELECT TOP 10 ... so that im running one query instead of ten ? etc etc

Anyways,
Thanks in advance,
Douglas

推荐答案

Y ^ HYS ^ YHU%^ TRHT

2 60 O *& ^ G& * ^ OGBV& VB ^^&

3 120 YE%
Y^HYS^YHU%^TRHT
2 60 O*&^G&*^OGBV&VB^^&
3 120 YE%


CC%


EYYEC%


这篇关于选择UNTIL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆