sql10

从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);

思路:title分组进行group by即可,count()函数进行计数。因为where语句后面不能接函数,所以

在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与聚合函数一起使用。

HAVING 子句可以让我们筛选分组后的各组数据。

select title,count(title) as t  from titles group by title//牛客BUG能通过

实际select title,count(title) as t  from titles group by title having t >=2

猜你喜欢

转载自blog.csdn.net/weixin_39137699/article/details/94218611