选择与另一个表连接的特定行

时间:2017-07-11 16:21:00

标签: mysql sql

我想从java.lang.NumberFormatException: For input string: "863092+01"

中获取数据

最简单的方法就是这样

Company

但是,我有另一张表"Select id from Company " Company Table id company 1 comA 2 comB 3 comC 通过company_id与Member Table相关联

Company Table

现在我想选择“拥有两名以上成员的公司”

(在这种情况下Member Table id company_id companymember 1 1 john 2 1 Tam 3 2 haya 4 1 lee 5 3 kih 6 3 wild comA有两个成员)

如何通过SQL实现?

2 个答案:

答案 0 :(得分:2)

您可以使用group byhaving

select company, count(*)
from Company a
inner join member b on a._id = b.company_id
group by company
having count(*) > 2

答案 1 :(得分:0)

SELECT 
  Company.company, count(*) 
FROM
  Company 
JOIN 
  Member on Company.id = Member.company_id 
GROUP BY 
  Company.company 
HAVING 
  count(*) > 2