我有一个包含名称字段和已批准字段的表。但是,多个条目可以具有相同的名称。我一直在尝试编写一个查找所有唯一名称的查询,并决定它是否没有批准的条目
我觉得我需要使用连接,但我只能真正加入它。有没有这样做的功能,我只是没有找到?或者我是否需要使用一些奇怪的联接来完成这项工作。
答案 0 :(得分:0)
define variable isApproved as logical no-undo.
for each customer no-lock break by name:
if first-of( name ) then isApproved = no.
if approved then isApproved = yes.
if last-of( name ) and isApproved = no then display name.
end.
答案 1 :(得分:0)
大约6个月前,我的问题与你的完全一样。我使用过这样的解决方案。希望它有所帮助。
DEF TEMP-TABLE tt-name NO-UNDO
FIELD name AS CHAR
FIELD approved AS LOG
INDEX ch-unique IS PRIMARY UNIQUE
name.
/* Create a list of unique customers */
FOR EACH customer FIELDS(name) NO-LOCK:
IF NOT CAN-FIND(FIRST tt-name
WHERE tt-name.name = customer.name) THEN DO:
CREATE tt-name.
ASSIGN tt-name.name = customer.name.
END.
END.
/* Look for at least one customer who matches name and not approved */
FOR EACH tt-name:
IF CAN-FIND(FIRST customer NO-LOCK
WHERE customer.name = tt-name.name
AND NOT customer.approved) THEN
ASSIGN tt-name.approved = NO.
ELSE
ASSIGN tt-name.approved = YES.
END.
/* Display the results */
FOR EACH tt-name
WHERE NOT tt-name.approved:
DISP tt-name WITH WIDTH 333 NO-ERROR.
END.