确定。它非常奇怪,我正在使用group_by并加入
这是我的查询。
SELECT *
FROM (`emp_skills` ES)
INNER JOIN `employee` E ON `E`.`employee_id`= `ES`.`employee_id`
INNER JOIN `ml_skill_type` MLST ON `MLST`.`skill_type_id` = `ES`.`ml_skill_type_id`
INNER JOIN `employment` ET ON `ET`.`employee_id` = `E`.`employee_id`
INNER JOIN `position_management` PM ON `PM`.`employement_id`=`ET`.`employment_id` AND PM.current=1
INNER JOIN `ml_designations` MLD ON `MLD`.`ml_designation_id`=`PM`.`ml_designation_id`
LEFT JOIN `assign_job` AJ ON `AJ`.`employee_id` = `E`.`employee_id`
LEFT JOIN `ml_projects` MLP ON `MLP`.`project_id` = `AJ`.`project_id`
GROUP BY `E`.`employee_id`
这里有结果我到目前为止。
但如果我使用它。
SELECT COUNT(*) AS numrows
然后我的查询变为
SELECT COUNT(*) AS numrows
FROM (`emp_skills` ES)
INNER JOIN `employee` E ON `E`.`employee_id`= `ES`.`employee_id`
INNER JOIN `ml_skill_type` MLST ON `MLST`.`skill_type_id` = `ES`.`ml_skill_type_id`
INNER JOIN `employment` ET ON `ET`.`employee_id` = `E`.`employee_id`
INNER JOIN `position_management` PM ON `PM`.`employement_id`=`ET`.`employment_id` AND PM.current=1
INNER JOIN `ml_designations` MLD ON `MLD`.`ml_designation_id`=`PM`.`ml_designation_id`
LEFT JOIN `assign_job` AJ ON `AJ`.`employee_id` = `E`.`employee_id`
LEFT JOIN `ml_projects` MLP ON `MLP`.`project_id` = `AJ`.`project_id`
GROUP BY `E`.`employee_id`
这是我得到的奇怪结果,我应该只得到1列和行,我想向我显示总行数。 但这就是我得到的。
如何修复此查询??
对不起,如果我无法解释我的问题..
这是带有注释掉的group_concat和group_by
的查询SELECT
`E`.`employee_id`,
`E`.`full_name`,
`MLD`.`designation_name`#,
#GROUP_CONCAT(DISTINCT MLP.project_title) AS Projects,
#GROUP_CONCAT(DISTINCT MLST.skill_name) AS EmployeeSkills
FROM (`emp_skills` ES)
INNER JOIN `employee` E ON `E`.`employee_id`= `ES`.`employee_id`
INNER JOIN `ml_skill_type` MLST ON `MLST`.`skill_type_id` = `ES`.`ml_skill_type_id`
INNER JOIN `employment` ET ON `ET`.`employee_id` = `E`.`employee_id`
INNER JOIN `position_management` PM ON `PM`.`employement_id`=`ET`.`employment_id` AND PM.current=1
INNER JOIN `ml_designations` MLD ON `MLD`.`ml_designation_id`=`PM`.`ml_designation_id`
LEFT JOIN `assign_job` AJ ON `AJ`.`employee_id` = `E`.`employee_id`
LEFT JOIN `ml_projects` MLP ON `MLP`.`project_id` = `AJ`.`project_id`
#GROUP BY `E`.`employee_id`
LIMIT 25
这是结果。 在上面的图像有16个记录,其中计数可以显示罚款。但如果使用group_concat和group_by,我会获得6条记录。
我真的想要,我不想要重复的员工姓名,而是我想要逗号分隔值等。
但是怎么知道查询从mysql返回多少行。
答案 0 :(得分:1)
如果您想知道总计数,则最后需要删除GROUP BY E.employee_id
。现在,您将获得每个不同employee_id
的汇总计数,而不是总计数。