我正在尝试按OrderID和lineID分组,并仅从包含单独字符串列表中的任何值的组中返回唯一的orderID和lineID。
这是一些示例数据。
OrderID lineID positionID fieldOfInterest somefield1 somefield2 ....
1A2 10248 1 '10xa' - -
1A2 10248 2 '42-vf' - -
1A2 10248 3 '10xb' - -
1A2 10249 2 '10xa' - -
1C3 11200 5 '10002' - -
1C3 10250 1 'N52O' - -
1V8 10250 7 'fas01' - -
1V8 10250 8 '10002' - -
. . . . . .
. . . . . .
. . . . . .
separate list to search groups against: ('10xa','10002')
我正在寻找的结果是
OrderID lineID
1A2 10248 <------ group contained '10xa'
1A2 10249 <------ group contained '10xa'
1C3 11200 <------ group contained '10002'
1V8 10250 <------ group contained '10002'
我努力了
having (min(fieldOfInterest) in ('10xa','10002')) or (max(fieldOfInterest) in ('10xa','10002'))
但我认为这不会一直有效。 也许我可以对字符串列表和表进行某种连接。
In Postgres, I would recommend aggregation and
bool_or()
: