我有两张桌子。一个是:
+--------------------------+-------------+------+-----+---------+
| Field | Type | Null | Key | Default |
+--------------------------+-------------+---------+-----+------+
| facility_id | int(10) | NO | PRI | NULL |
| facility_name | varchar(30) | | | NULL |
| facility_model | varchar(25) | | | NULL |
+--------------------------+-------------+------+-----+---------+
另一个是:
+--------------------------+-------------+------+-----+---------+
| Field | Type | Null | Key | Default |
+--------------------------+-------------+---------+-----+------+
| facility_id | int(10) | NO | PRI | NULL |
| facility_serial_number | varchar(30) | | | NULL |
+--------------------------+-------------+------+-----+---------+
不同的设施可能有相同的设施序列号(这是我们想要找出并修复的)。我想获取其设施序列号多次出现的设施的所有信息。
我尝试使用 group by 并具有:
select f1.facility_id, f1.facility_name, f1.facility_model, f2.facility_serial_number
from f1, f2 on f1.facility_id = f2.facility_id
group by f2.facility_serial_number
having count (facility_serial_number) > 2
这是错误的。我也尝试了其他方法,但没有成功。corerct 查询语法是什么?