hive的SQL练习3

根据如上表格信息,实现如下需求:

  1. 查询五一期间(2023-05-01 ~ 2023-05-07),每个餐厅的订单总数量及排名
  2. with t as (
    select *,
    count(1) over(partition by restaurant_id) countNum
    from orders where substr(order_date,1,10)
    between '2023-05-01' and '2023-05-07'
    )
    select distinct restaurant_id,countNum,dense_rank() over (order by countNum desc) pm from t
    order by pm ;
  3. 查看最近一个月内在一家餐厅重复购买 3 次以上的餐厅名字、用户名字、购买次数
  4. with t as (
    select restaurant_id,user_id,
    count(1) buyCount
    from orders
    where substr(order_date,1,10) >= add_months(`current_date`(),-1)
    and substr(order_date,1,10) <=`current_date`()
    group by restaurant_id,user_id
    having buyCount >=3
    )
    select
    r.restaurant_name,
    u.user_name,
    t.buyCount
    from t left join restaurants r on t.restaurant_id=r.restaurant_id
    left join `users` u on t.user_id=u.user_id;
相关推荐
卷毛迷你猪1 天前
快速实验篇(A11)数据集成与多维分析:从单实验产出到跨实验宽表
hive·hadoop
漂着的圆木1 天前
Agent 功能参与度:Copilot 怎么算
sql·数据分析·agent·githubcopilot·度量
旺仔不是程序员2 天前
LIMIT 1:PostgreSQL 只取一行的高效查询姿势
数据库·后端·sql
卷毛迷你猪2 天前
快速实验篇(A10)短序列上 SPI 的失效机制
hadoop
知识的搬运工旺仔2 天前
唯一索引与 NULL 值:PostgreSQL 主键约束与 NULLS NOT DISTINCT
数据库·后端·sql·postgresql
Francek Chen2 天前
【大数据处理与分析】数据仓库Hive:04 数据仓库Hive概述
大数据·数据仓库·hive·hadoop·分布式
想念是会呼吸的鱼2 天前
【ClickHouse 常用 SQL 语句整理】
sql·clickhouse
Gl�ria3 天前
Hadoop/YARN 集群缩容:下线DN节点
大数据·hadoop·分布式
想念是会呼吸的鱼3 天前
MySQL 常用语法整理
sql·mysql