Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL选择多个OR语句的位置_Sql_Postgresql_Select - Fatal编程技术网

PostgreSQL选择多个OR语句的位置

PostgreSQL选择多个OR语句的位置,sql,postgresql,select,Sql,Postgresql,Select,我有下面的PgSQL查询,在其中我查找user_id等于我要查找的一组id中的任意一个 问题是,有没有一种方法可以简化这个语句,这样我就不必一直把user_id= SELECT * FROM comments WHERE session_id=1 AND (user_id=10 OR user_id=11 OR user_id=12 OR user_id=13 OR user_id=14 OR user_id=15 OR user_id=16) 或者,

我有下面的PgSQL查询,在其中我查找user_id等于我要查找的一组id中的任意一个

问题是,有没有一种方法可以简化这个语句,这样我就不必一直把user_id=

SELECT * 
FROM comments 
WHERE session_id=1 
AND (user_id=10 OR user_id=11 
     OR user_id=12 OR user_id=13 
     OR user_id=14 OR user_id=15 
     OR user_id=16)
或者,对于这种特定情况:

SELECT * 
FROM comments 
WHERE session_id=1 
  AND user_id between 10 and 16;
SELECT * 
FROM comments 
WHERE session_id=1 
  AND user_id between 10 and 16;