SQL语法错误或接近 “ORDER”

问题描述:

这里是我的代码SQL语法错误或接近 “ORDER”

SELECT 
    customerid, numseats, fistname, surname, totalcost 
FROM 
    leadcutomer, flightbooking; 
ORDER BY 
    'totalcost' DESC; 

我得到的错误是:

ERROR: syntax error at or near "ORDER"

我使用PG管理员4,什么是错的呢?

+5

多余的';'在第二行methinks结束。 –

+0

[踢坏的习惯:使用旧式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins。 aspx) - 在ANSI - ** 92 ** SQL标准(** 25年**之前)中将旧式*逗号分隔的表*样式列表替换为* proper * ANSI'JOIN'语法不鼓励使用 –

+2

'ORDER BY'totalcost'' ...这是告诉Postgres按字符串排序,这没有多大意义。改为使用'ORDER BY totalcost'。 –

您在查询中遇到多个问题。我会写这样的:

SELECT customerid, numseats, firstname, surname, totalcost 
FROM leadcutomer l JOIN 
    flightbooking b 
    ON ?? = ?? 
ORDER BY totalcost DESC; 

的具体问题:

  • 你正在做一个CROSS JOIN和帽子可能是不希望。
  • 您在FROM子句中使用逗号而不是正确的显式JOIN语法。
  • FROM子句末尾有一个分号。
  • 您按照常数而不是列来排序。
+0

SELECT客户ID,numseats,名字,姓氏,TOTALCOST FROM leadcustomer升JOIN flightbooking b ON customer.customerid =客户ID ORDER BY DESC TOTALCOST; –

+0

我缺少一个从表客户条款项,我在做什么错 –

+0

@PeterHorvath'customer' 'leadcustomer'?。 –