【问题标题】:Inner join in postgresqlpostgresql中的内部连接
【发布时间】:2019-12-18 16:08:41
【问题描述】:

我正在执行下面的查询,查询抛出一个错误(错误:“内部”或附近的语法错误)

如果我缺少任何东西,有人可以帮助我

SELECT a.*
FROM table1 a where a.snapshot_date='2019-07-31'
inner join table2 b 
ON a.snapshot_date=b.snapshot_date

【问题讨论】:

  • 请在代码问题中给出minimal reproducible example--剪切&粘贴&可运行代码;具有期望和实际输出的示例输入(包括逐字错误消息);标签和版本;明确的规范和解释。这包括您可以提供的最少代码,即您显示的代码可以通过您显示的代码扩展为不可以。 (调试基础。)对于包含 DBMS/产品和 DDL 的 SQL,其中包括约束和索引以及表格格式的基表初始化。 PS你有一个语法错误。阅读语法和手册。显示组成子表达式是好的。

标签: postgresql join inner-join


【解决方案1】:

您的where 子句出现故障:

SELECT a.*
FROM table1 a
inner join table2 b 
ON a.snapshot_date=b.snapshot_date
where a.snapshot_date='2019-07-31'

编辑:如果您想要来自table2 的信息,您还应该将其添加到select 而不仅仅是来自table1 的内容:

SELECT *
FROM table1 a
inner join table2 b 
ON a.snapshot_date=b.snapshot_date
where a.snapshot_date='2019-07-31'

【讨论】:

    【解决方案2】:

    连接用于指定源,而不是 where 子句的一部分

    试试

    SELECT a.*
    FROM table1 a inner join table2 b 
    ON a.snapshot_date=b.snapshot_date
    where a.snapshot_date='2019-07-31'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-25
      • 2012-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      • 2012-12-09
      • 2020-12-14
      相关资源
      最近更新 更多