我有一个有效的MySQL查询,只能获得#34; Managers Only"来自我的tblUsers:
SELECT COUNT(e.username) AS employeeCount,
m.username AS reports_to,
m.id
FROM tblusers e
INNER JOIN tblusers m
ON e.reportsToID = m.ID
GROUP BY m.username
但是我需要另一个只能获得"仅限员工"?
的查询答案 0 :(得分:2)
感谢所有人,特别是@crai
您的查询运行良好:
SELECT username, id, reportstoID
FROM tblusers
WHERE id NOT IN (SELECT reportsToID FROM tblusers) AND reportstoID <> '0'
ORDER BY username
答案 1 :(得分:0)
SELECT
username
, id
, reportsToID
FROM
tblusers e
WHERE
e.reportsToID<>0
ORDER BY username