如果sql使用COUNT()计算特定人员,我应该如何知道这些选定人员使用此查询使用他们的ID? 例如,如果它计算了5个nonhmsonboard,那么他们/他们的ID是什么?
SELECT long_posname,
COUNT(
CASE WHEN employment_status LIKE 'ON BOARD' and trim(groupID)='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) AS 'hmsonboard',
COUNT(
CASE WHEN employment_status LIKE 'VACATION' and trim(groupID)='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) AS 'hmsonvacation',
COUNT(
CASE WHEN employment_status LIKE 'ON BOARD' and trim(groupID)='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) + COUNT(
CASE WHEN employment_status LIKE 'VACATION' and trim(groupID)='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) AS 'hmstotal',
COUNT(
CASE WHEN employment_status LIKE 'ON BOARD' and trim(groupID)!='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) AS 'nonhmsonboard',
COUNT(
CASE WHEN employment_status LIKE 'VACATION' and trim(groupID)!='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) AS 'nonhmsonvacation',
COUNT(
CASE WHEN employment_status LIKE 'ON BOARD' and trim(groupID)!='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) + COUNT(
CASE WHEN employment_status LIKE 'VACATION' and trim(groupID)!='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) AS 'nonhmstotal',
COUNT(
CASE WHEN employment_status LIKE 'ON BOARD'
THEN 1
ELSE NULL
END ) + COUNT(
CASE WHEN employment_status LIKE 'VACATION'
THEN 1
ELSE NULL
END ) AS 'total', crewID
FROM (
SELECT tb_crew_master.groupID, tb_crew_master.crewID, MAX( date_arrive ) , tb_crew_master.empstatID, pl_employment_status.employment_status, long_posname, pos_arrangement, tb_crew_master.posID
FROM tb_crew_master
INNER JOIN tb_crew_seaservice ON tb_crew_master.crewID = tb_crew_seaservice.crewID
INNER JOIN pl_position ON pl_position.posID = tb_crew_master.posID
INNER JOIN pl_employment_status ON pl_employment_status.empstatID = tb_crew_master.empstatID
INNER JOIN tb_vessel ON tb_vessel.vesID = tb_crew_seaservice.vesID
INNER JOIN pl_vessel_type ON pl_vessel_type.vestypeID = tb_vessel.vestypeID
WHERE tb_crew_master.is_inactive = 'N' and pl_vessel_type.vestypeID='typ249225370585e575f8'
GROUP BY tb_crew_seaservice.crewID
) AS t
GROUP BY posID
ORDER BY pos_arrangement
答案 0 :(得分:0)
不确定但使用crewID
列(假设来自您发布的查询代码)或其他任何内容
相应表格中的ID
列(来自pl_employment_status
表的ID列),如
SELECT crewID,
long_posname,
COUNT(
CASE WHEN employment_status LIKE 'ON BOARD'
and trim(groupID)='grp320952d8919d763a8'
THEN 1
ELSE NULL
END ) AS 'hmsonboard',
.......
<Rest of your code>
.........
GROUP BY crewID,long_posname
ORDER BY pos_arrangement