题目描述
从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);
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);
输入描述:
无
输出描述:
title | t |
---|---|
Assistant Engineer | 2 |
Engineer | 4 |
省略 | 省略 |
Staff | 3 |
SQL:
select title,count(title) as t from titles group by title having t>=2
用count和group by 统计同一条数据