我寫了一個查詢,以獲得用戶的設備總數。但當我為單個用戶運行查詢時,它作業得很好。當我保持多個電子郵件地址時,它不作業,得到的訊息是子查詢不應該包含多個。我無法改變下面的查詢以接受多個值。誰能在這方面提供幫助?
select distinct UserDisplayName, [UserName/Mail],SerialNumber,LastSeen as Lastcheckin,Model, EnrollmentStatus, (select count(*) from Intunedevices where [ UserName/Mail] in
('[email protected]'/span>,'[email protected]'/span>) group by UserDisplayName) as EMSCOUNT
from Intunedevices where [UserName/Mail] in ('[email protected]'/span>,
'[email protected]')
uj5u.com熱心網友回復:
問題是你的子查詢中的group by正在回傳多條記錄。它可能應該是correlated - 我不完全確定,因為in的標準略有不同,這是不是你的樣本資料中的一個錯字?
嘗試以下方法:
select distinct
用戶顯示名稱(UserDisplayName)。
[UserName/Mail]。
序列號。
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 ('[email protected]'/span>,'[email protected]'/span>)
uj5u.com熱心網友回復:
不要使用DISTINCT,只要在你的外層查詢中使用GROUP BY,然后你可以聚合任何非分組的列,例如:
select UserDisplayName,
[UserName/Mail]。
序列號。
LastSeen as Lastcheckin,
模型。
EnrollmentStatus。
count(*) EMSCOUNT
from Intunedevices
where [UserName/Mail] in ('[email protected]'/span>, '[email protected]'/span>)
group by UserDisplayName,
[UserName/Mail]。
序列號。
LastSeen,
模型。
注冊狀態
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/314534.html
標籤:
下一篇:添加缺失的資料
