简体   繁体   English

错误:“关键字‘ORDER’附近的语法不正确。”

[英]ERROR: 'Incorrect syntax near the keyword 'ORDER'.'

I'm getting an error from my SQL query:我的 SQL 查询出现错误:

SELECT TOP 20 * FROM 
    (
      SELECT DISTINCT
         p.ItemGroupName, p.Varenummer, s.EAN, s.inventoryQuantity 
      FROM 
        ShopInventory s, ProductData p
     WHERE s.EAN = p.EAN
) 
ORDER BY cast(inventoryQuantity AS int) DESC

ERROR: 'Incorrect syntax near the keyword 'ORDER'.'

Probably, you just need to give the subquery an alias:可能,你只需要给子查询一个别名:

SELECT TOP 20 * FROM 
    (
      SELECT DISTINCT
         p.ItemGroupName, p.Varenummer, s.EAN, s.inventoryQuantity 
      FROM 
        ShopInventory s, ProductData p
     WHERE s.EAN = p.EAN
) mytable
ORDER BY cast(inventoryQuantity AS int) DESC

Some would say you are using the old join syntax instead of the recommended JOIN clause but for the purposes of solving your question I think thats a bit of a distraction.有人会说您使用的是旧的连接语法而不是推荐的 JOIN 子句,但为了解决您的问题,我认为这有点让人分心。 If you're interested in INNER JOIN, OUTER JOIN and all that you can read up here: What is the difference between "INNER JOIN" and "OUTER JOIN"?如果您对 INNER JOIN、OUTER JOIN 以及您可以在此处阅读的所有内容感兴趣: “INNER JOIN”和“OUTER JOIN”有什么区别?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM