首页 > 试题广场 >

快件信息表(waybillinfo)中存储了快件的所有操作信

[单选题]
快件信息表waybillinfo(id, waybillno, zonecode, optype, update_time)中存储了快件的所有操作信息,请找出在'中山公园'网点,异常派送(optype='异常派件')次数超过3次的快件(waybillno),正确的sql为()
  • select waybillno, count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件'
    and count(waybillno) >3
  • select waybillno, count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件'
    order by waybillno having count(*) > 3
  • select waybillno, count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件'
    having count(*) > 3
  • select waybillno from waybillinfo where zonecode='中山公园' and optype='异常派件'
    group by waybillno having count(*) > 3

<p>聚集查询,需要用having对group by分组的结果进行过滤</p>

编辑于 2020-07-04 21:00:07 回复(0)
1、where之后不能以函数作为条件
2、3、    having 是对 group by后的数据进行筛选过滤,必须要有group by才能用having。
编辑于 2020-03-23 11:47:14 回复(4)
大概复现了一下数据库表格式,那个waybillno其实是快递件的唯一标志,需要查询在中山公园异常派件的快递的单号,然后因为是聚集查询的结果,需要用having对group by的查询结果做过滤。
发表于 2019-10-17 17:40:10 回复(8)

having只能对group by的结果进行操作

having只用来在group by之后,having不可单独用,必须和group by用

2.拿着where指定的约束条件,去文件/表中取出一条条记录

3.将取出的一条条记录进行分组group by,如果没有group by,则整体作为一组

4.将分组的结果进行having过滤

编辑于 2020-08-11 10:33:21 回复(1)
查询的是快件(waybillno),所以ABC直接排除
发表于 2020-04-09 18:28:09 回复(1)
where 不能跟聚合函数,所以A错;
having子句必须和group by一起适应,所以B/C错。
发表于 2021-02-08 11:11:56 回复(0)
1、where之后不能以函数作为条件
2、3、    having 是对 group by后的数据进行筛选过滤,必须要有group by才能用having。
发表于 2021-10-26 22:54:07 回复(1)
C错在没有加group by。如果使用聚合函数却不加group by,就是对整张表做聚合计算,这时select后面不能有除了聚合函数以外的字段。但题目明显不是对整张表做聚合计算。
发表于 2021-08-01 19:41:24 回复(0)
1 where之后不能使用聚集函数count作为条件
发表于 2020-10-21 15:08:03 回复(0)
<p>聚合函数只能用在group by后面,a排除,having只能和 group by 搭配b,c排除,选D</p>
发表于 2020-07-22 21:43:01 回复(0)
SQL的执行顺序是FROM(including JOINs) ---> WHERE ---> GROUP BY ---> HAVING ---> SELECT ---> DISTINCT ---> ORDER BY ---> LIMIT/OFFSET,即先where筛选后,再按ORDER BY来分组。故D选项中where zonecode='中山公园' and optype='异常派件'group by waybillno having count(*) > 3,先筛选出了异常派送optype='异常派件'的快件,再按照快件分组,最终count(*) > 3统计出的就是异常派件数量大于3的快件。D选项准确。
编辑于 2022-02-20 15:43:17 回复(0)
having 用在 group by之后
发表于 2023-09-08 00:05:30 回复(0)
没看懂,D选项 having后出现的count(*)没有在select选项中出现呀
发表于 2023-06-01 16:08:30 回复(0)
1.having只用来在group by之后,对group by的结果进行筛选,不能单独用 2.分组结果统计需要用group by,每个快件整体作为一组
发表于 2023-04-11 09:24:40 回复(0)
having必须和groupby语句一起使用。C语法就不对。
发表于 2021-10-08 21:45:28 回复(0)
having只能对group by的结果进行操作 having只用来在group by之后,having不可单独用,必须和group by用 2.拿着where指定的约束条件,去文件/表中取出一条条记录 3.将取出的一条条记录进行分组group by,如果没有group by,则整体作为一组 4.将分组的结果进行having过滤 https://blog.csdn.net/weixin_34268753/article/details/85990663
发表于 2021-09-28 11:05:01 回复(0)
选项D是错的吧,
select waybillno from waybillinfo where zonecode='中山公园' and optype='异常派件'
group by waybillno having count(*) > 3   中的分组要先有聚合函数,正确应该是
select  waybillno,count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件'
group by waybillno having count(*) > 3  
发表于 2021-08-04 13:51:58 回复(0)
where后不能跟聚合函数
发表于 2021-06-21 15:49:34 回复(0)
Count聚合函数,需要用group by,不能用where
发表于 2021-03-09 15:55:08 回复(0)
<p>A where 后面有聚合函数</p>
发表于 2021-01-06 21:29:20 回复(0)