首页 > 试题广场 >

从titles表获取按照title进行分组

[编程题]从titles表获取按照title进行分组
  • 热度指数:127807 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
有一个titles表简况如下:

从titles表获取按照title进行分组,每组个数大于等于2,给出title以及对应的数目t。


示例1

输入

输出

此题应注意以下三点:
1、用COUNT()函数和GROUP BY语句可以统计同一title值的记录条数
2、根据题意,输出每个title的个数为t,故用AS语句将COUNT(title)的值转换为t
3、由于WHERE后不可跟COUNT()函数,故用HAVING语句来限定t>=2的条件
SELECT title, COUNT(title) AS t FROM titles
GROUP BY title HAVING t >= 2

编辑于 2017-07-12 20:06:31 回复(22)
SELECT title, COUNT(*) AS t FROM titles 
GROUP BY title 
HAVING COUNT(*) >= 2;
发表于 2019-03-18 10:30:53 回复(0)
SELECT title,count(emp_no) t
FROM titles
GROUP BY title
HAVING count(emp_no)>=2;
1.观看题意可知。一个title下面有多个emp_no。所以数目t的真实列名应该为emp_no

发表于 2019-08-06 16:54:11 回复(2)
SELECT title,count(emp_no) as t
FROM titles
GROUP BY title
HAVING t>=2
发表于 2017-09-24 16:01:50 回复(2)
1、关键词:title分组、每组个数大于等于2
2、语句
select title, count(title) as t
from titles
group by title
having t >= 2
order by title
3、总结
本题主要考察group by 和 having 的用法
编辑于 2020-08-02 14:53:27 回复(0)
select title,count(title) as t from titles group by title having t > 1

1.count() 该聚合函数用于计数
2.group by 用于分组,且需要写于判断条件having前
3. 由于 t 是聚合函数的别名, 因此该判断条件应当用having


发表于 2018-10-08 20:02:35 回复(0)
select title ,count(*) t from titles group by title having t >=2;
发表于 2017-12-08 15:42:40 回复(1)
select titles.title,count(*) as t
from titles
group by title
having t>=2;
编辑于 2020-10-08 18:28:59 回复(0)

这题目不严谨,我这都通过了,可能后台数据都是超过2的

select title,count(title)
from titles
group by title;

正确的应该是这样的

select title,count(title) as t
from titles
group by title
having t >= 2;
发表于 2020-07-01 11:41:24 回复(0)
//和之前那题基本一样,甚至还简单了,不要求排除掉相同的emp_no
select title,count(*) t
from titles
group by title
having count(*)>=2;

发表于 2020-06-06 10:37:45 回复(0)
Select title , count (group by title ) as t and t >2
发表于 2020-04-29 13:02:52 回复(0)
select title, count(emp_no) as t
from titles
group by title
having count(emp_no)>= 2

发表于 2019-06-26 23:46:06 回复(0)
从titles表中选择title字段,然后还需要计算每个部门的个数,即(count(title))
第一句:select title,count(title) as t  # 此处t是题目要求标记所以用as为t
然后选择表titles,用from
第二句:from titles
再然后  题目说分组title还要计算每个分组的title有多少,so
第三句:group by title 
第四句:having t>=2

个人感觉理解题目要求更难 啊啊  

发表于 2019-03-23 21:39:26 回复(0)
SELECT
    titles.title,
    count(titles.title) AS t
FROM
    titles
GROUP BY
    title;
发表于 2018-06-30 11:36:09 回复(2)
1、通过Group By分组
2、通过Having控制分组条件
发表于 2018-02-09 12:00:25 回复(0)
SELECT 
	title,
	COUNT(1) AS t
FROM 
    titles
GROUP BY 
	title

发表于 2017-09-15 15:43:42 回复(1)
select distinct(title) as title,count(title) as t
from titles having  t > 2;

用distinct去重复现实总个数,出来的结果是senior engineer 6没有理解为什么不行
发表于 2021-02-03 23:13:32 回复(0)
select title,count(1) t
from titles
group by title
having count(1)>=2

发表于 2021-01-30 15:01:11 回复(0)
select title,count(title) as t from titles group by title having t >= 2;
发表于 2021-01-30 14:51:52 回复(0)
SELECT title,COUNT(*) AS t
FROM titles
GROUP BY title
HAVING COUNT(*) >= 2
easy!!!
发表于 2021-01-20 22:17:29 回复(0)