sql - SQL Server - 选择语句包括变量
问题描述
这是使用变量并最终显示 Vol1 >0 和 vol1 <=10 之间的记录数的正确方法吗?
declare @x int;
set @x=0;
select
case when vol1 > 0 and vol1 <=10 then x = x + 1 end
from coverage
group by vol1
print @x
解决方案
如果我理解正确,您需要在 中分配变量select
并摆脱group by
,因此查询仅返回一行:
declare @x int;
set @x = 0;
select @x = count(*)
from coverage
where vol1 > 0 and vol1 <= 10;
print @x;
推荐阅读
- excel - UserForm01.Show 代码中的错误 91“对象变量或未设置块变量”
- sql - 我无法使用外键关系来整理我的数据。截断子数据后被截断
- java - 如何在两个表 ReactJS 中发布
- amazon-web-services - 将域 A 记录指向 EC2 并使用 HTTPS 服务
- java - 将两个不同的数组与不同的数据结合起来
- c++ - 为什么 std::span 缺少比较运算符?
- javascript - ThreeJS切割ExtrudeGeometry形状深度的角落
- c++ - target_include_directories() does not find header files
- swift - 使用 JSONDecoder 时出现 EXC_BAD_INSTRUCTION 错误
- java - Elasticsearch - 从 2.x 升级到 7.x - 使用 TransportClient 和 Jest 进行双重写入