我有一个表,上面写着'Employee‘,只有一个字段叫'Name’。假设表中有9条记录。我需要在“where”子句的帮助下编写一个“for each”查询,通过它我可以在第一个位置查看/显示一个选定的名称(比如“Sheldon”是9个记录中的第6个),其余8个记录(名称)按字母顺序排列。**注意:仅通过构造这样的查询。没有临时表、缓冲区的概念。除了“display”语句之外,“for each”块中不允许任何其他语句。
发布于 2014-09-21 05:12:38
我认为您是在说您有一个employee表,其中包含如下记录:
Dan
Gus
Mike
Paul
Rich
Sheldon
Shelley
William
Xavier并且您希望输出为:
Sheldon
Dan
Gus
Mike
Paul
Rich
Shelley
William
Xavier您不能在单个FOR EACH中执行此操作,因为您有两个完全不同的查询。一个用于查找"sheldon“记录(或多个记录--您没有说过它们是否是唯一的),另一个用于查找所有其他记录。
你可以这样做:
do with frame a.
for each employee no-lock where name = "Sheldon":
display name with frame a 10 down.
down with frame a.
end.
for each employee where name <> "Sheldon" by name:
display name with frame a.
down with frame a.
end.
end.(“处理帧a”和各种其他“帧a”比特只是使用单个帧。如果你不关心这一点,你就不需要这些东西了。)
如果你愿意扩展一下你的视野,并屈尊使用FIND,你可以这样做:
find employee no-lock where name = "sheldon".
repeat:
if not available employee then leave.
display name with 10 down.
if name = "sheldon" then
find first employee no-lock where name <> "sheldon" no-error.
else
find next employee where name <> "sheldon" no-error.
end.发布于 2014-10-01 09:14:49
由于显而易见的原因,我没有花太多的时间来测试它,但这个卑劣的把戏似乎是:
for each employee where name = "sheldon" or name <> "sheldon":
display name.
end.就像我说的--我会用这个作为取消资格的测试。如果你是这样想的,那么你的代码就麻烦多了。我的天。
发布于 2014-09-21 01:50:11
通常情况下,你会使用一个FIND,但既然你要求的是一个for EACH --这里有一个不在其中的方法。你可以很容易地添加它来获得你想要的任何最终结果。
FOR EACH employee
NO-LOCK
BY Employee.name:
DISPLAY employee.name WITH DOWN.
END.https://stackoverflow.com/questions/25951408
复制相似问题