mysql - 检查一个字段中的所有记录是否具有相同的值?
问题描述
select count(*) from step where job_id =31 ;
select count(*) from step where job_id =31 and status =2;
这是两个查询。我想知道在单个查询中是否count1
相等count2
解决方案
select count(*) as jobCount,
sum(status = 2) as statusCount,
count(*) - sum(status = 2) as countDifference,
(count(*) - sum(status = 2)) = 0 as isEqual
from step
where job_id = 31;
推荐阅读
- redmine - 在 Redmine 中安装积压插件时出错
- three.js - 用three.js使相对面的交叉边缘平行
- javascript - React 状态只返回一个元素
- algorithm - 找到最大的子矩阵,矩阵中只包含一个零和一
- angular - OneSignal,Ionic 4 - 除非应用重新启动,否则不会调用 getPermissionSubscriptionState()
- javascript - 在 webpack 和 babel 构建的 node_modules 中,console.log 的源映射中断
- onelogin - 启动 OneLogin 示例节点应用程序时出现问题
- python - 打印一行后,时间睡眠不循环工作
- javascript - 查找不包含在另一个对象数组中的数组中的元素
- ruby-on-rails - 验证名称没有制表符或反斜杠 - Rails