我在 Postgres 表中有 6 列:
A1 character varying(5)[]
A2 character varying(5)[]
A3 int REFERENCES ... -- FK
B1 character varying(5)[]
B2 character varying(5)[]
B3 int REFERENCES ... -- FK
Run Code Online (Sandbox Code Playgroud)
我需要一个SELECT
匹配的第一行是获胜者(限制为 1)并匹配 A 组和 B 组。
我知道 Postgres 不关心WHERE
子句的顺序,我必须准备一个ORDER
子句或找到不同的方法。
我想准备匹配优先级的查找,我的WHERE
子句重要性如下:
highest priority: (A1 and B1) OR
. (A1 and B2 OR A2 and B1) OR
. (A1 and B3 OR A3 and B1) OR
. (A2 and B3 OR A3 and B2) OR …
Run Code Online (Sandbox Code Playgroud)