首页 > 其他分享 >group by 专题

group by 专题

时间:2022-10-05 10:44:24浏览次数:48  
标签:count 专题 group max id select quantity

1. 涉及 “最多/最大”,即比其他所有(all)都大(>=):

常和 having count() 搭配,作为一个判断条件;还可搭配 max(),all() 。

力扣586:

select customer_number
from Orders 
group by customer_number 
having count(*)>=
    all(select count(*)
        from Orders
        group by customer_number)

select customer_number
from Orders 
group by customer_number 
having count(*)=
    (select max(cnt)
    from   
        (select count(*) as cnt 
        from Orders
        group by customer_number) as tmp)

力扣1076:

select project_id
from Project,Employee
where Project.employee_id = Employee.employee_id
group by project_id
having count(*) >= all
    (select count(*)
    from Project,Employee
    where Project.employee_id = Employee.employee_id
    group by project_id)

力扣1867:

select order_id
from
    (select order_id,
        max(avg_quantity) over() as max_avg_quantity,
        max_quantity
    from
        (select order_id,
            avg(quantity) as avg_quantity,
            max(quantity) as max_quantity
        from OrdersDetails
        group by order_id) as t1) as t2
where max_avg_quantity < max_quantity

2. 涉及多字段聚合:即 group by A, B...

力扣1149:

select distinct viewer_id as id
from Views
group by view_date,viewer_id
having count(distinct article_id )>=2
order by id

力扣1193:

select left(trans_date,7) as month,country,
    count(*) as trans_count,
    sum(if(state='approved',1,0)) as approved_count,
    sum(amount) as trans_total_amount,
    sum(if(state='approved',amount,0)) as approved_total_amount
from Transactions
group by month,country

力扣1308:

select gender,day,sum(sum_score_points) over(partition by gender order by day) as total
from
    (select gender,day,sum(score_points) as sum_score_points
    from Scores
    group by gender,day) as tmp
order by gender,day

-END

标签:count,专题,group,max,id,select,quantity
From: https://www.cnblogs.com/peitongshi/p/16755191.html

相关文章

  • DP专题
    分治优化DP分治优化1D/1Ddp对于一类\[f(x)=\min_{k=y}^{x-1}w(l,r)\]即所有\(w(l,r)\)事先已知,且\(f(x)\)满足决策单调性(即\(w(l,r)\)满足区间包含单......
  • 背包专题
    P01:01背包问题题目有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。......
  • 报告分享|2021中国实体零售数字化专题报告
    全文链接:http://tecdat.cn/?p=28716原文出处:拓端数据部落公众号 作者:MingjiTang统计学中传统的数据类型有截面数据和时间序列数据。这两者都只能在某一纵向或横向上......
  • where in 专题
    查找一个字段,通常是通过主键回表带回,需避免没有带回的写法。力扣1174:#1.首次订单withtmpas(select*fromDeliverywhere(customer_id,order_date)in(sel......
  • 搜索专题杂练
    2022/10 主要是搜索专题的好题洛谷P2329[SCOI2005]栅栏二分+dfs洛谷P1120小木棍爆搜+剪枝用桶存一下木棍,记录最大最小。深搜的状态:\(\text{sum-}\)目前拼的......
  • 计算机视觉与图形学-神经渲染专题-StructNeRF室内重建
    (说明:如果您认为下面的文章对您有帮助,请您花费一秒时间点击一下最底部的广告以此来激励本人创作,谢谢!!!)神经辐射场(NeRF)通过密集捕获的输入图像实现照片真实感视图合成。然而,......
  • SQL中GROUP BY语句介绍
    本文主要介绍SQL(StructuredQueryLanguage)中GROUPBY语句的相关知识,同时通过用法示例介绍GROUPBY语句的常见用法。1概述GROUPBY语句通常用于配合聚合函数(如COUNT......
  • 个人数论专题总结
    中国剩余定理(CRT)证明与应用问题定义给定一组同余方程:\[(S):\begin{cases}x≡a_1(\text{mod}m_1)\\x≡a_2(\text{mod}m_2)\\……\\x≡a_n(\text{mod}m_n)\\\end{cases......
  • Netty 学习(六):创建 NioEventLoopGroup 的核心源码说明
    Netty学习(六):创建NioEventLoopGroup的核心源码说明作者:Grey原文地址:博客园:Netty学习(六):创建NioEventLoopGroup的核心源码说明CSDN:Netty学习(六):创建NioEventLoopG......
  • 窗口函数专题
    窗口函数之“最大/最小”问题,可和groupby互相改写。力扣1070:selectdistinctproduct_id,yearasfirst_year,quantity,pricefrom(select*,rank()over(......