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

      <legend id='lawiW'><style id='lawiW'><dir id='lawiW'><q id='lawiW'></q></dir></style></legend>
      • <bdo id='lawiW'></bdo><ul id='lawiW'></ul>

        <tfoot id='lawiW'></tfoot>

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

        选择计数(*);

        SELECT COUNT(*) ;(选择计数(*);)

          <tbody id='1xoP1'></tbody>

          <tfoot id='1xoP1'></tfoot>

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

            <small id='1xoP1'></small><noframes id='1xoP1'>

                  <bdo id='1xoP1'></bdo><ul id='1xoP1'></ul>
                  本文介绍了选择计数(*);的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个数据库,database1,里面有两个表(Table 1Table2).

                  I have a database, database1, with two tables (Table 1, Table2) in it.

                  Table1 中有 3 行,Table2 中有 2 行.现在,如果我在 database1 上执行以下 SQL 查询 SELECT COUNT(*);,则输出为 "1".

                  There are 3 rows in Table1 and 2 rows in Table2. Now if I execute the following SQL query SELECT COUNT(*); on database1, then the output is "1".

                  有人知道这个"1"是什么意思吗?

                  Does anyone has the idea, what this "1" signifies?

                  两个表的定义如下.

                  CREATE TABLE Table1
                  (
                  ID INT PRIMARY KEY,
                  NAME NVARCHAR(20)
                  )
                  
                  CREATE TABLE Table2
                  (
                  ID INT PRIMARY KEY,
                  NAME NVARCHAR(20)
                  )
                  

                  推荐答案

                  与此类似,以下内容也返回结果.

                  Along similar lines the following also returns a result.

                  SELECT 'test'
                  WHERE  EXISTS (SELECT *)  
                  

                  该行为的解释(来自 此连接项)也适用于您的问题.

                  The explanation for that behavior (from this Connect item) also applies to your question.

                  在 ANSI SQL 中,不允许使用没有 FROM 子句的 SELECT 语句 -您需要指定表源.所以语句 "SELECT 'test'WHERE EXISTS(SELECT *)" 应该给出语法错误.这是正确的行为.

                  In ANSI SQL, a SELECT statement without FROM clause is not permitted - you need to specify a table source. So the statement "SELECT 'test' WHERE EXISTS(SELECT *)" should give syntax error. This is the correct behavior.

                  关于 SQL Server 实现,FROM子句是可选的,它一直以这种方式工作.所以你可以做"SELECT 1" 或 "SELECT @v" 等等,不需要表格.在在其他数据库系统中,有一个名为DUAL"的虚拟表 ,其中有一个row 用于执行诸如SELECT 1 FROM"之类的 SELECT 语句dual;" 或 "SELECT @v FROM dual;".现在,来到 EXISTS 子句 -项目列表在语法或结果方面无关紧要查询和 SELECT * 在子查询中是有效的.将此与事实上,我们允许 SELECT 而没有 FROM,你会得到你想要的行为看.我们可以修复它,但这样做并没有多大价值可能会破坏现有的应用程序代码.

                  With respect to the SQL Server implementation, the FROM clause is optional and it has always worked this way. So you can do "SELECT 1" or "SELECT @v" and so on without requiring a table. In other database systems, there is a dummy table called "DUAL" with one row that is used to do such SELECT statements like "SELECT 1 FROM dual;" or "SELECT @v FROM dual;". Now, coming to the EXISTS clause - the project list doesn't matter in terms of the syntax or result of the query and SELECT * is valid in a sub-query. Couple this with the fact that we allow SELECT without FROM, you get the behavior that you see. We could fix it but there is not much value in doing it and it might break existing application code.

                  这篇关于选择计数(*);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                  <legend id='oJaEQ'><style id='oJaEQ'><dir id='oJaEQ'><q id='oJaEQ'></q></dir></style></legend>
                  <i id='oJaEQ'><tr id='oJaEQ'><dt id='oJaEQ'><q id='oJaEQ'><span id='oJaEQ'><b id='oJaEQ'><form id='oJaEQ'><ins id='oJaEQ'></ins><ul id='oJaEQ'></ul><sub id='oJaEQ'></sub></form><legend id='oJaEQ'></legend><bdo id='oJaEQ'><pre id='oJaEQ'><center id='oJaEQ'></center></pre></bdo></b><th id='oJaEQ'></th></span></q></dt></tr></i><div id='oJaEQ'><tfoot id='oJaEQ'></tfoot><dl id='oJaEQ'><fieldset id='oJaEQ'></fieldset></dl></div>

                    <tbody id='oJaEQ'></tbody>
                  <tfoot id='oJaEQ'></tfoot>
                    <bdo id='oJaEQ'></bdo><ul id='oJaEQ'></ul>

                      • <small id='oJaEQ'></small><noframes id='oJaEQ'>