总之,我面临加入mysql的问题。我想得到一个计数唯一数量的结果 staff_id
使用分组依据的字段。如果我运行这个查询,一步就能得到我想要的结果。
SELECT id,staff_id,note,warning_date FROM tbl_warning GROUP BY staff_id HAVING (count(staff_id) > 0);
下一步,我想再连接两个表以获得字段,例如 tbl_employment
. com_id
作为 comid
, tbl_staff
. name
, tbl_staff
. gender
但结果是重复的。 ``SELECTtbl_warning
.
id,
tbl_warning.
staff_id,
tbl_warning.
note,
tbl_warning.
warning_date,
tbl_employment.
com_idas
comid,
tbl_staff.
name,
tbl_staff.
genderFROM
tbl_warningJOIN
tbl_employmentON
tbl_employment.
staff_id=
tbl_warning.
staff_idJOIN
tbl_staffON
tbl_staff.
id=
tbl_warning.
staff_idHAVING (SELECT
staff_idFROM
tbl_warningGROUP BY
staff_idHAVING (count(staff_id) > 1));
我要唯一的结果相同的第一个屏幕截图。谢谢您!
1条答案
按热度按时间brjng4g31#
您应该联接到按计数查找匹配人员的子查询: