postgres sql 选择两列的组合

kli*_*ind 3 sql

用户可以选择选项组合列表,然后搜索它们。

sql 可能看起来像这样。

select * from p where (option_type = 'X' and value = 'A') 
or (option_type = 'X' and value = 'B')
or (option_type = 'Y' and value = 'D')
Run Code Online (Sandbox Code Playgroud)

但当然我不想有 n 个 or 的

一个好的 sql 看起来如何执行???用户可以选择多种选项组合。

谢谢。

a_h*_*ame 6

不需要多个 OR:

select * 
from p 
where (option_type, value) in ( ('X' ,'A'), ('X','B'), ('Y','D') ) 
Run Code Online (Sandbox Code Playgroud)