导致 PostgreSQL 9.3 语法错误的代码有什么问题

What is wrong with this code that is causing Syntax Error in PostgreSQL 9.3

下面是我写的一段SQL代码。我想将两条记录合并为一条记录,其中第一条记录域显示为 "From source",第二条记录的域变为 "To Domain"。我需要做更多的过滤,但为什么这个简单的语句不起作用?

我收到一个错误 "Syntax error at end of input"

*SELECT 
   "ID" , "Time",  "Source Domain", "To Domain" From
   (SELECT "RecordID" As "ID","UTCTimestamp" As "Time","Domain" As "Source Domain" FROM public."Traffic - Mobile")T1
   Inner Join Lateral
   (SELECT "Domain" As "To Domain" FROM public."Traffic - Mobile" where "RespondentID"="T1"."RespondentID" )T2*

提前致谢

PostgreSQL 版本 9.3

我认为您仍然需要一个 ON 子句,因为它是一个 INNER JOIN。如果您不想指定 ON 子句,我认为您可以改用 CROSS JOIN

例如

SELECT 
   "ID" , "Time",  "Source Domain", "To Domain" From
   (SELECT "RecordID" As "ID","UTCTimestamp" As "Time","Domain" As "Source Domain"
          FROM public."Traffic - Mobile")T1
   Inner Join Lateral
   (SELECT "Domain" As "To Domain" FROM public."Traffic - Mobile"
           where "RespondentID"="T1"."RespondentID" )T2
    ON true

我认为你把这个复杂化了。 table 的简单自连接就足够了。您不需要派生 table 来重命名列

SELECT "ID", "Time", t1."Domain" as "Source Domain", t2."Domain" as "To Domain" 
from public."Traffic - Mobile" as t1
  join public."Traffic - Mobile" as t2 on t2."RespondentID" = t1."RespondentID";