如何获取秒 table 中有两个 phone 数字的员工姓名和 ID
How to get employee name and id who have two phone numbers in second table
这是两个table1.emp_table, 2.phone_table。
如何获取第二个 table
中有两个 phone 数字的员工姓名和 ID
SELECT t1.id,
t1.name
FROM emp_table t1
INNER JOIN -- the join will remove employees who do not have
( -- two phone numbers in phone_table
SELECT Id
FROM phone_table -- this query identifies all employees
GROUP BY Id -- having two phone numbers in phone_table
HAVING COUNT(*) = 2
) t2
ON t1.id = t2.Id
这是两个table1.emp_table, 2.phone_table。 如何获取第二个 table
中有两个 phone 数字的员工姓名和 IDSELECT t1.id,
t1.name
FROM emp_table t1
INNER JOIN -- the join will remove employees who do not have
( -- two phone numbers in phone_table
SELECT Id
FROM phone_table -- this query identifies all employees
GROUP BY Id -- having two phone numbers in phone_table
HAVING COUNT(*) = 2
) t2
ON t1.id = t2.Id