ysql 允许使用多个where子句,组合where子句允许使用两种方式使用:AND 和OR子句的方式使用.
数据库中的操作符号:AND , OR , IN , NOT.

AND:
SELECT * FROM products WHERE products.vend_id = 1003 AND products.prod_price <= 10;

OR:
SELECT * FROM products WHERE products.vend_id = 1002 OR products.vend_id = 1003 ;

IN:
建议能使用IN的子句中不使用OR,IN行性能好,方便理解.
SELECT * FROM products WHERE products.vend_id IN (1002,1003);

NOT:
Mysql对NOT的支持仅在对IN,BETWEEN,EXISTS子句取反,这与其他多数数据库对各种条件都支持不同.
SELECT * FROM products WHERE products.vend_id NOT IN (1002,1003);

注意:
在同时有AND和OR的子句中,mysql是优先处理AND操作的.一般建议使用()来确定处理顺序和消除歧义.
比如: SELECT * FROM products WHERE (products.vend_id= 1002 OR products.vend_id=1003) AND prod_price >= 10;

相关文章:

  • 2022-01-03
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-12-29
  • 2021-11-14
  • 2021-05-01
  • 2022-01-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案