2
我想這兩個SQL查詢相結合,以顯示與1層的在這也有2的ITEMID和1合併兩個SQL查詢 - COUNT和WHERE
訪問接入列最高計數的用戶名我將如何結合這兩個陳述來產生這個結果?
顯示具有最高權限的帳戶:
SELECT UserName, COUNT(Access) AS Count
FROM Permissions
GROUP BY UserName, Access
HAVING Access = 1
ORDER BY Count DESC
Result:
Username AccessCount
user1 2
user2 1
user3 2
顯示所有賬戶數據管理器訪問:
SELECT UserName FROM Permissions
where itemid = 2 AND Access = 1
Result:
Username
user1
user2
權限表樣本數據:
itemID UserName Access
1 user1 1
2 user1 1
3 user1 1
1 user2 0
2 user2 1
3 user2 0
1 user3 1
2 user3 0
3 user3 1
其結果將是user1,因爲他們可以訪問itemID 2和最高訪問次數。