nowcoder SQL

—> 中位数

—> 查找每个公司薪水中位数的员工

数据&建表

create table employee
(
    id      int,
    company varchar(11),
    salary  int
);

insert into employee (id, company, salary)
values (1, 'A', 2341),
       (2, 'A', 341),
       (3, 'A', 15),
       (4, 'A', 15314),
       (5, 'A', 451),
       (6, 'A', 513),
       (7, 'B', 15),
       (8, 'B', 13),
       (9, 'B', 1154),
       (10, 'B', 1345),
       (11, 'B', 1221),
       (12, 'B', 234),
       (13, 'C', 2345),
       (14, 'C', 2645),
       (15, 'C', 2645),
       (16, 'C', 2652),
       (17, 'C', 65);

原表 employee

idcompanysalary
1A2341
2A341
3A15
4A15314
5A451
6A513
7B15
8B13
9B1154
10B1345
11B1221
12B234
13C2345
14C2645
15C2645
16C2652
17C65

需求:查找每个公司薪水中位数的员工

代码编写

select *
from (
         select id,
                salary,
                row_number() over (partition by company order by salary) as rn,
                count(1) over (partition by company)                     as cnt
         from employee
     ) t1
where rn in (floor((cnt + 1) / 2), floor((cnt + 2) / 2))
idcompanysalary
5A451
6A513
12B234
9B1154
14C2645

—> 牛客直播课分析

—> 牛客直播各科目出勤率

链接

with a as (
    select course_id,
           course_name
    from course_tb
),
     b as (
         select course_id,
                count(distinct if(timestampdiff(minute, in_datetime, out_datetime) >= 10, user_id, null)) as flag
         from attend_tb
         group by course_id
     ),
     c as (
         select course_id,
                sum(if(if_sign = 1, 1, 0)) as cnt
         from behavior_tb
         group by course_id
     )
select a.course_id,
       a.course_name,
       round(b.flag * 100 / c.cnt, 2) as rate
from a
         join b on a.course_id = b.course_id
         join c on a.course_id = c.course_id
order by a.course_id

—> 某音短视频

—> 近一个月发布的视频中热度最高的top3视频

链接

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值