sql - this Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >=
问题描述
i wrote a query to get total count of devices for user. but when i run the query for single user it working fine. when i keep mutiple emailids its not working getting message subquery should not contain multiple. I unable to change below query to accept multiple values. Can anyone help on this.
select distinct UserDisplayName,[UserName/Mail],SerialNumber,LastSeen as Lastcheckin,Model, EnrollmentStatus,(select count(*) from Intunedevices where [UserName/Mail] in
('aaa-xyz.onsite-caller@xyz.com','gbidi.i.habab@gsk.com') group by UserDisplayName) as EMSCOUNT
from Intunedevices where [UserName/Mail] in ('aaa-xyz.onsite-caller@xyz.com',
'gbidi.i.habab@xyz.com')
解决方案
问题是group by
在您的子查询中返回多行。它可能应该是相关的 - 我不完全确定,因为in
标准略有不同,这是您的样本数据中的错字吗?
尝试以下操作:
select distinct
UserDisplayName,
[UserName/Mail],
SerialNumber,
LastSeen as Lastcheckin,Model,
EnrollmentStatus,
(select count(*) from Intunedevices d where d.[UserName/Mail] = id.[UserName/Mail] and d.UserDisplayName = id.UserDisplayName) as EMSCOUNT
from Intunedevices id
where id.[UserName/Mail] in ('aaa-xyz.onsite-caller@xyz.com','gbidi.i.habab@xyz.com')
推荐阅读
- mysql - 如何避免在mysql视图的子视图中进行全表扫描
- django - 如何在 django 中为用户登录实现自定义身份验证
- react-native - this.nameOfFunction 调用时不是函数
- python - 如何在将列表与另一个变量进行比较时引用列表中的多个项目?
- cube - 是否可以在 TM1s.cfg 的 DataBaseDirectory 参数中使用相对路径?
- progressive-web-apps - 第二次刷新后正在存储缓存
- kubernetes - Kubernetes PVC 删除 POD 的内容
- apache-flink - 失去检查点协调员后是否有可能恢复
- java - 不同类方法的组成
- reactjs - 在 goDaddy 主机上上传由 create-react-app 创建的 react 应用程序的步骤