Why does quot;select count(*)quot; from nothing return 1(为什么“选择计数(*)?从无返回 1)
问题描述
使用 SQL Server 2012:
使用大师选择 *收益
<块引用>必须指定要从中选择的表
这正是我所期望的.
但有趣的是
使用大师选择计数(*)返回 1.
有人可以向我解释一下这里计算的是什么吗?
并可能包括来源...
SQL Server(在幕后)有效地将 from 应用于只有一行的虚拟表.因此,您的计数将得到 1.
选择测试"会做同样的事情,例如,返回 'test' 一次.
就像 Oracle 中的 DUAL 表、DB2 中的 SYSDUMMY1 等.
根据要求,这里有几个关于此主题的 MS Connect 链接:
点击更多点击>
With SQL Server 2012 :
use master
select *
yields
Must specify table to select from
which is exactly what I would expect.
But the funny thing is that
use master
select count(*)
returns 1.
Can someone explain to me what is counted here?
Edit : And possibly include sources...
SQL Server is (behind the curtain) effectively applying a from to a dummy table, which has only one row. Thus you will get 1 for your count.
select 'test'
will do the same thing, as an example, return 'test' one time.
It's like the DUAL table in Oracle, SYSDUMMY1 in DB2, etc.
As requested, here's a couple of links to MS Connect on this topic:
ClickyMore Clicky
这篇关于为什么“选择计数(*)"?从无返回 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么“选择计数(*)"?从无返回 1
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
