從titles表擷取按照title進行分組,每組個數大于等于2,給出title以及對應的數目t。
CREATE TABLE IF NOT EXISTS “titles” (
emp_no
int(11) NOT NULL,
title
varchar(50) NOT NULL,
from_date
date NOT NULL,
to_date
date DEFAULT NULL);
having過濾條件 t >= 2;
select title , count(emp_no) as t
from titles
group by title
having t >= 2;
從titles表擷取按照title進行分組,每組個數大于等于2,給出title以及對應的數目t。
注意對于重複的emp_no進行忽略。
CREATE TABLE IF NOT EXISTS
titles
(
emp_no
int(11) NOT NULL,
title
varchar(50) NOT NULL,
from_date
date NOT NULL,
to_date
date DEFAULT NULL);
distinct去掉重複emp_no
select title , count(distinct emp_no) as t
from titles
group by title
having t >= 2;