【问题标题】:Postgres multiple columns in WHERE col1, col2 INPostgres 多列在 WHERE col1, col2 IN
【发布时间】:2015-12-02 04:13:07
【问题描述】:

我可以轻松做到:

select * from cities where name in ('Paris', 'London');

但我也可以选择包含列组合的行吗?

select * from cities where city, country in (('Paris', 'France'), ('London', 'UK'))

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:

    是的,但你必须使用括号:

    select * from cities where (city, country) in (('Paris', 'France'), ('London', 'UK'))
    

    语法是“复合值”的语法。见manual

    复合值的外部文本表示由根据各个字段类型的 I/O 转换规则解释的项目以及指示复合结构的装饰组成。装饰由整个值周围的括号((和))以及相邻项之间的逗号(,)组成。

    【讨论】:

      猜你喜欢
      • 2020-01-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 1970-01-01
      • 2013-02-28
      • 1970-01-01
      • 2013-09-17
      • 2016-01-04
      相关资源
      最近更新 更多