Postgres查询错误:错误:语法错误在或附近"选择"

时间:2018-05-02 11:04:03

标签: postgresql syntax-error

我收到以下内容:

查询错误:

  

错误:语法错误在或附近"选择"第4行:(选择remoteaddr,   count(remoteaddr)remoteaddrCount

Select Tim1.remoteaddr,Tim1.remoteaddrCount,  Tim2.domain_id
From domain_visitors

(Select remoteaddr, count(remoteaddr) remoteaddrCount
From domain_visitors
Group by remoteaddr
Having count(remoteaddr)>500) Tim1,

(Select distinct remoteaddr, domain_id
From domain_visitors) Tim2
Where Tim1.remoteaddr=Tim2.remoteaddr

2 个答案:

答案 0 :(得分:0)

domain_visitors之后和子查询之前,似乎您有一个热情的表名From

让我们再试一次

Select Tim1.remoteaddr,Tim1.remoteaddrCount, Tim2.domain_id From 
(Select remoteaddr, count(remoteaddr) remoteaddrCount From domain_visitors Group by remoteaddr Having count(remoteaddr)>500) Tim1
JOIN 
(Select distinct remoteaddr, domain_id From domain_visitors) Tim2 ON Tim1.remoteaddr=Tim2.remoteaddr

希望这个答案可以帮到你。

答案 1 :(得分:0)

您在FROM的第一个表格与创建Tim1的表达式

之间缺少逗号
Select Tim1.remoteaddr,Tim1.remoteaddrCount, Tim2.domain_id 
From domain_visitors,  -- <-- MISSING COMMA 
  (Select remoteaddr, count(remoteaddr) remoteaddrCount 
     From domain_visitors 
     Group by remoteaddr 
     Having count(remoteaddr)>500) Tim1,
  (Select distinct remoteaddr, domain_id 
     From domain_visitors) Tim2 
Where Tim1.remoteaddr=Tim2.remoteaddr