Mysql 除语句错误外

Mysql 除语句错误外,mysql,sql,mssql,t-sql,Mysql,Sql,Mssql,T Sql,我不明白为什么这个查询不起作用: SELECT product.maker, product.model, product.type FROM product EXCEPT (Select top 3 with ties product.maker, product.model, product.type FROM Product ORDER BY model DESC) 数据库方案由四个表组成: Product(maker, model, type) PC(code, model, sp

我不明白为什么这个查询不起作用:

SELECT product.maker, product.model, product.type FROM product EXCEPT
(Select top 3 with ties product.maker, product.model, product.type  
FROM Product ORDER BY model DESC)
数据库方案由四个表组成:

Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)

更新:我实际上试着在im-in在线站点中使用mssql输入此代码,但仍然不起作用。是否可能是站点错误(即,他们的DBMS有问题)。*“不存在”似乎也不起作用,但是我以前在网站上的其他查询问题中使用过它。

Yoy也可以尝试此查询

SELECT product.maker, product.model, product.type FROM product 
    MINUS
Select top 3 with ties product.maker, product.model, product.type  
FROM Product ORDER BY model DESC.
希望通过这个你能达到预期的效果。

除了和TOP是()关键字。您是否使用问题标签中提到的MSSQL或MySQL。如果您试图在MySQL上运行此查询,这就是错误的原因,因为MySQL不支持这些关键字

在MySQL中,尝试以下等效方法:

SELECT DISTINCT 
         product.maker, 
         product.model, 
         product.type FROM product 
         LEFT JOIN 
            (SELECT DISTINCT product.maker, product.model, product.type  
              FROM Product 
              ORDER BY model DESC
              LIMIT 3
             ) as p2
             ON product.maker=p2.maker
                AND product.model = p2.model
                AND product.type = p2.type
          WHERE p2.maker IS NULL
                AND p2.model IS NULL
                AND p2.type IS NULL
注意:我已将
DISTINCT
添加到要模拟的主查询中:

Exception从左侧查询返回任何不相同的值 在正确的查询中也可以找到


还向子查询中添加了
DISTINCT
,以模拟运行时收到的错误消息?关键字“EXCEPT”附近的语法不正确。我确实不太确定。我认为这两种方法都有效。如果不是因为我的代码有关系而可能重复最愚蠢的注释,这并不意味着这是同一个问题-\uhi,我厌倦了运行你的代码,但是我得到了:关键字“Select”附近的语法不正确代码可能是错误的,因为我没有你的模式。但是概念是正确的,mysql不支持kayword,所以你必须使用另一种方法。是的,我实际上包括了模式,但有人删除了它。现在我又添加了一次,我不认为模式部分有任何问题,但仍然不起作用。。。我觉得很奇怪,之前的NOT EXIST查询不起作用谢谢,我实际上不知道我使用的是mysql还是sql。我实际上是在线查询问题……我认为这个网站同时运行mysql和sql。我真想知道为什么除了和不存在不起作用。更新:在站点中,它还允许我选择要使用的dbms,由于某些原因,它也不能与mssql一起工作:(