SQL - 如何计算特定列中的数字出现次数,同时还选择其他列

时间:2017-10-07 23:41:22

标签: sql

我正在尝试计算如何从员工总数中计算女性和男性员工的数量,并将它们放在员工总数旁边的单独列中。这是我的代码:

select cd.dept_no, d.dept_name, count(cd.dept_no) as 'No. Current 
Employees', e.gender from current_dept_emp as cd
inner join departments as d on cd.dept_no = d.dept_no
inner join employees as e on e.emp_no = cd.emp_no
where cd.to_date = '9999-01-01'
group by cd.dept_no, e.gender
order by cd.dept_no

返回以下结果

screen

如何获得所需的输出?

1 个答案:

答案 0 :(得分:0)

使用条件聚合:

<?php
error_reporting(0);
$item_id = $_GET["item_id"];
session_start();
if (!empty($_SESSION["incart"])) {
    foreach ($_SESSION["incart"] as $select => $val) {
        if($val["item_id"] == $item_id)
        {
            unset($_SESSION["incart"][$select]);
        }
    }
}
?>