<small id='cxjzl'></small><noframes id='cxjzl'>

      <i id='cxjzl'><tr id='cxjzl'><dt id='cxjzl'><q id='cxjzl'><span id='cxjzl'><b id='cxjzl'><form id='cxjzl'><ins id='cxjzl'></ins><ul id='cxjzl'></ul><sub id='cxjzl'></sub></form><legend id='cxjzl'></legend><bdo id='cxjzl'><pre id='cxjzl'><center id='cxjzl'></center></pre></bdo></b><th id='cxjzl'></th></span></q></dt></tr></i><div id='cxjzl'><tfoot id='cxjzl'></tfoot><dl id='cxjzl'><fieldset id='cxjzl'></fieldset></dl></div>
      <legend id='cxjzl'><style id='cxjzl'><dir id='cxjzl'><q id='cxjzl'></q></dir></style></legend>

          <bdo id='cxjzl'></bdo><ul id='cxjzl'></ul>
        <tfoot id='cxjzl'></tfoot>
      1. 在查询中使用 except 时出现语法错误

        Syntax error when using except in a query(在查询中使用 except 时出现语法错误)
          <i id='qhost'><tr id='qhost'><dt id='qhost'><q id='qhost'><span id='qhost'><b id='qhost'><form id='qhost'><ins id='qhost'></ins><ul id='qhost'></ul><sub id='qhost'></sub></form><legend id='qhost'></legend><bdo id='qhost'><pre id='qhost'><center id='qhost'></center></pre></bdo></b><th id='qhost'></th></span></q></dt></tr></i><div id='qhost'><tfoot id='qhost'></tfoot><dl id='qhost'><fieldset id='qhost'></fieldset></dl></div>
          • <tfoot id='qhost'></tfoot>
          • <legend id='qhost'><style id='qhost'><dir id='qhost'><q id='qhost'></q></dir></style></legend>

            <small id='qhost'></small><noframes id='qhost'>

              <tbody id='qhost'></tbody>

                <bdo id='qhost'></bdo><ul id='qhost'></ul>

                  本文介绍了在查询中使用 except 时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  此查询有效:

                  mysql> SELECT s.sno FROM students s;  
                  +------+  
                  | sno  |   
                  +------+   
                  |    1 |   
                  |    2 |   
                  |    3 |   
                  |    4 |   
                  |    5 |    
                  |    6 |    
                  |    7 |   
                  |    8 |   
                  |    9 |   
                  |   10 |   
                  +------+   
                  10 rows in set (0.00 sec)  
                  

                  这个查询也有效:

                  mysql> SELECT t.sno FROM take t WHERE t.cno = 'CS112';  
                  +------+  
                  | sno  |  
                  +------+  
                  |    1 |  
                  |    2 |  
                  |    3 |  
                  |    4 |  
                  +------+   
                  4 rows in set (0.00 sec)  
                  

                  但是这个查询:

                  SELECT s.sno FROM students s    
                  EXCEPT    
                  SELECT t.sno FROM take t WHERE t.cno = 'CS112';  
                  

                  因错误而失败:

                  mysql> SELECT s.sno FROM students s  
                      -> EXCEPT  
                      -> SELECT t.sno FROM take t WHERE t.cno = 'CS112';  
                  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that   corresponds to your MySQL server version for the right syntax to use n   
                  ear 'EXCEPT   
                  SELECT t.sno FROM take t WHERE t.cno = 'CS112'' at line 2 
                  

                  我在这里做错了什么?

                  推荐答案

                  我不相信 MySQL 支持 EXCEPT 语法.尝试使用 NOT INLEFT JOIN:

                  I don't believe MySQL supports EXCEPT syntax. Try using NOT IN or a LEFT JOIN:

                  SELECT s.sno 
                  FROM students s    
                  WHERE s.sno NOT IN 
                  (
                      SELECT t.sno 
                      FROM take t 
                      WHERE t.cno = 'CS112'
                  );
                  

                  SELECT s.sno 
                  FROM students s    
                      LEFT JOIN take t ON s.sno = t.sno
                  WHERE IFNULL(t.cno, '') != 'CS112'
                  

                  更新

                  我模拟了你的数据,它正确地返回了 5 到 10:

                  I mocked up your data as such and it correctly returns 5 through 10:

                  create temporary table temp_students (sno int)
                  
                  insert into temp_students values (1)
                  insert into temp_students values (2)
                  insert into temp_students values (3)
                  insert into temp_students values (4)
                  insert into temp_students values (5)
                  insert into temp_students values (6)
                  insert into temp_students values (7)
                  insert into temp_students values (8)
                  insert into temp_students values (9)
                  insert into temp_students values (10)
                  
                  create temporary table temp_take (sno int, cno varchar(50))
                  
                  insert into temp_take values (1, 'CS112')
                  insert into temp_take values (2, 'CS112')
                  insert into temp_take values (3, 'CS112')
                  insert into temp_take values (4, 'CS112')
                  
                  SELECT s.sno 
                  FROM temp_students s    
                          LEFT JOIN temp_take t ON s.sno = t.sno
                  WHERE IFNULL(t.cno, '') != 'CS112'
                  

                  这篇关于在查询中使用 except 时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                      • <bdo id='BFVya'></bdo><ul id='BFVya'></ul>

                        <i id='BFVya'><tr id='BFVya'><dt id='BFVya'><q id='BFVya'><span id='BFVya'><b id='BFVya'><form id='BFVya'><ins id='BFVya'></ins><ul id='BFVya'></ul><sub id='BFVya'></sub></form><legend id='BFVya'></legend><bdo id='BFVya'><pre id='BFVya'><center id='BFVya'></center></pre></bdo></b><th id='BFVya'></th></span></q></dt></tr></i><div id='BFVya'><tfoot id='BFVya'></tfoot><dl id='BFVya'><fieldset id='BFVya'></fieldset></dl></div>
                          <tbody id='BFVya'></tbody>

                        <small id='BFVya'></small><noframes id='BFVya'>

                          <tfoot id='BFVya'></tfoot>
                          • <legend id='BFVya'><style id='BFVya'><dir id='BFVya'><q id='BFVya'></q></dir></style></legend>