如何编写查询以显示具有该专业的规范ID和人员数量

时间:2019-04-07 07:46:18

标签: sql oracle

编写查询以显示专业ID,具有该专业的员工人数  那些拥有2名以上员工的专业中,将新列命名为Num with Speciality。按特殊顺序按Num升序显示

$data = $this->Static_model->get_static_data();
$data['pages'] = $this->Pages_model->get_pages();
$data['categories'] = $this->Categories_model->get_categories();
COLUMN COUNT(specid) HEADING "Num with Speciality"
SELECT id.specid, 
       count(specname) "Num with Speciality"
FROM staff_speciality id,speciality
WHERE staff_speciality > 2
ORDER BY specid  ASC;

1 个答案:

答案 0 :(得分:2)

尝试通过以下方式拥有

SELECT SPECID,
       count(*) "Num with Speciality"
FROM staff_speciality 
GROUP BY SPECID
HAVING count(*) > 2