​LeetCode刷题实战569:员工薪水中位数

SAP 针对不同行业(制造业、零售业、金融业)推出了专属的云解决方案,以下是各行业的核心方案与特点 SAP推出行业专属云解决方案:制造业(SAP Digital Manufacturing Cloud)提供AI排产与质量预警,降低缺陷率;零售业(S/4HANA Cloud零售版)实现AI预测补货与全渠道库存同步,减少浪费;金融业(Business ByDesign)支持合规自动化与实时风控,降低审计成本。各方案均采用云原生架构,典型案例显示实施效果显著。 阅读详情

算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !

今天和大家聊的问题叫做 员工薪水中位数,我们先来看题面:

https://leetcode-cn.com/problems/median-employee-salary/

表信息

下面的员工表包含全部的员工ID,公司名称以及每个员工的薪水。

The Employee Table holds all employees. The employee table has three columns: Employee Id, Company Name, and Salary.

ef1c0bfd13bf6fd87f714608fc361ac8.png

Table: Employee

找出各公司薪水的中位数。

Write a SQL query to find the median salary of each company. Bonus points if you can solve it without using any built-in SQL functions.

38d4d1c1333aa22def8a97317e8d24e4.png

查询结果

解题

https://zhuanlan.zhihu.com/p/257081415

WITH t AS(
SELECT *, 
ROW_NUMBER() OVER(PARTITION BY Company ORDER BY Salary) AS num
from Employee),

t1 AS(
SELECT Company AS company_id, 
MAX(num)/2 AS criteria_1, 
MAX(num)/2+1 AS criteria_2, 
ROUND(MAX(num)/2) AS criteria_3
FROM t
GROUP BY Company),

t2 AS(
SELECT * FROM t LEFT JOIN t1 ON t.Company = t1.company_id)

SELECT Id,Company,Salary
FROM t2
WHERE num = criteria_1
OR num = criteria_2
OR num = criteria_3;

好了,今天的文章就到这里,如果觉得有所收获,请顺手点个在看或者转发吧,你们的支持是我最大的动力 。

上期推文:

LeetCode1-560题汇总,希望对你有点帮助!

LeetCode刷题实战561:数组拆分 I

LeetCode刷题实战562:矩阵中最长的连续1线段

LeetCode刷题实战563:二叉树的坡度

LeetCode刷题实战564:寻找最近的回文数

LeetCode刷题实战565:数组嵌套

LeetCode刷题实战566:重塑矩阵

LeetCode刷题实战567:字符串的排列

LeetCode刷题实战568:最大休假天数

7262d38ac08fde5a9760f2fd95ed85d0.png

HyperLynx仿真(一)LineSim简单介绍 可以选择设置信号线与信号线之间默认的距离和信号线与同平面的平面之间的距离,这些设置根据工程师项目上经常使用的情况而设置,也可以选择不设置,在每次仿真时根据需要再对每一个仿真单独设置。仿真属性的设置对话框包含一般设置、 显示颜色设置、LineSim 设置、BoardSim 设置、 层叠默认设置、焊盘类型设置、仿真示波器默认设置、电路仿真器默认设置、电源完整性设置及高级设置。第一次使用HyperLynx软件时需要设置仿真相关环境,包括仿真软件的基本设置、模型库路径设置、仿真控制器控制、单位等。... 阅读详情

相关推荐

智能问数产品背后的Agent技术揭秘:从任务分解到工具调用的完整流程

本文深入解析智能问数产品背后的Agent技术,从任务分解到工具调用的完整流程。通过大模型驱动的语义理解和动态工具调度,Agent系统能高效处理复杂数据分析需求,显著提升响应速度和准确率。文章详细介绍了模块化架构、任务分解机制、动态工具调用及双通道记忆系统等核心技术,展示了大模型时代的新型数据分析范式。

weixin_30399821的博客 440

LeetCode 569.员工薪水中位数

写一个SQL查询,找出每个公司的工资中位数。

weixin_51696882的博客 189

离线迁移 Conda 环境到 Windows 服务器:用 conda-pack 摆脱硬路径限制

在进行深度学习算法的环境部署时,由于生产服务器被彻底隔离外网,只能把conda中env文件夹中的虚拟环境文件夹从开发机直接拷到Windows 服务器,但在运行labelimg等工具时可能报错,因此用conda-pack来解决。

weixin_44115575的博客 1428

【Leetcode】569. 员工薪水中位数

Employee 表包含所有员工。Employee 表有三列:员工Id,公司名和薪水。请编写SQL查询来查找每个公司的薪水中位数。 +-----+------------+--------+ |Id | Company | Salary | +-----+------------+--------+ |1 | A | 2341 | |2 | A | 341 | |3 | A | 15 | |4 | A

qq_33412699的博客 239

迈德威视相机调用( 基于 Linux系统+ OpenCV )

迈德威视相机调用( 基于 Linux系统+ OpenCV )前言一、登录迈德威视官网,下载官方SDK二、代码调用与视频帧处理( 基于 OpenCV )总结 前言     此博客记录了迈德威视工业相机在 Linux 系统下的代码调用及其环境配置,通过 OpenCV 对视频帧进行处理。   一、登录迈德威视官网,下载官方SDK      迈德威视官网 : http://www.mindvision.com.cn/     1. 进入官网后,在服务支持中选择软件下载。    2. 选择Linux系统S.

kkkkkk0729的博客 5681

Python 3.13.7 (64-bit)安装弹窗提示:Setup failed:0x80070643 - 安装时发生严重错误...如何解决?

🏆本文收录于 《全栈Bug调优(实战版)》 专栏,该专栏专注于分享我在真实项目开发中遇到的各类疑难Bug及其深层成因,并系统提供高效、可复现的解决思路和实操方案。无论你是刚入行的新手开发者,还是拥有多年项目经验的资深工程师,本专栏都将为你提供一条系统化、高质量的问题排查与优化路径,助力你加速成长,攻克技术壁垒,迈向技术价值最大化与职业发展的更高峰🚀!

**My Coding Family** 2123

569. 员工薪水中位数 - 力扣(LeetCode)

代码中首先使用了一个子查询来为每个公司的工资数据进行排序并计算总数。

qq_58114907的博客 1466

【网络安全】SSRF漏洞讲解

SSRF漏洞讲解一、初识SSRF漏洞1.定义2.产生原理3.会导致的危害4.常见产生SSRF的地方5.常见缺失函数二、SSRF漏洞利用1.函数(1) file_get_contents(2)fsockopen()(3) curl_exec()2.协议(1)file协议(2)http协议(3)dict协议(4)gopher协议三、绕过1.绕过方式(1)检查IP是否为内网IP(2)Host获取与DNS绕过(3)通过各种协议(4)利用URL解析器滥用问题四、修复修复方案五、小结 一、初识SSRF漏洞 1.定义

你在看屏幕的同时,屏幕也在注视着你 3182

力扣题解-569. 员工薪水中位数

SQL架构 Employee 表包含所有员工。Employee 表有三列:员工Id,公司名和薪水。 以下为数据: Create table If Not Exists Employee (Id int, Company varchar(255), Salary int) Truncate table Employee insert into Employee (Id, Company, Salary) values ('1', 'A', '2341') insert into Employee (Id,

戳一下有机会获得一份额外加个蛋的蛋炒饭 650

AI Agent Harness自动化漏洞扫描

本文要介绍的AI Agent Harness自动化漏洞扫描方案,正是为了解决传统漏扫的上述痛点而生。漏洞检出率提升35%以上,逻辑漏洞检出率从不足30%提升到92%误报率从27%降到3%以下,人工复核成本降低90%支持自定义业务系统、IoT、工控等多场景资产扫描,适配成本降低80%内置反馈学习机制,扫描效果越用越好AI Agent是指具备自主感知、决策、行动能力的大模型驱动程序,它可以根据给定的目标,自主调用工具、规划步骤、完成任务。

AI 原生应用开发的博客 479

RK3568平台开发系列讲解(音频篇)配置声卡

📢本篇文章介绍如何配置声卡。

内核笔记 2452

力扣569.员工薪水中位数笔记

(取中位数方法二:用rk >= cnt/2 and rk <= cnt/2 +1)1. floor((cnt + 1)/2) 和floor((cnt+2)/2)(6+1)/2 =3.5----向下取整为3,(6+2)/2 = 4----向下取整为4.(5+2)/2=3.5----向下取整为3.(5+1)/2=3----向下取整为3,row_number 计算排名。count计算每一公司的总人数。2. 当cnt=6,3. 当cnt=5,

skylar0的博客 199

RK3588多核NPU并行加速yolo优化教程:基于线程池的高性能推理实现

本教程详细介绍了RK3588多核NPU的并行加速优化方法。RK3588搭载三个独立NPU核心,总计算能力达6TOPS,但传统单线程方式无法充分发挥其性能。文章从硬件架构分析入手,详细讲解了三核心独立处理架构和多种工作模式,并通过代码示例展示了线程池技术的实现原理。线程池通过预创建工作线程、任务队列和条件变量等核心组件,避免了频繁创建线程的开销,能显著提升NPU的并行处理效率。教程还提供了性能计算公式和内存带宽优化策略,帮助开发者最大化利用RK3588的硬件算力,实现高性能AI推理。

LXY_LOVE36的博客 1025

leetcode569. 员工薪水中位数

Employee表包含所有员工。Employee表有三列:员工Id,公司名和薪水。 +-----+------------+--------+ |Id | Company | Salary | +-----+------------+--------+ |1 | A | 2341 | |2 | A | 341 | |3 ...

qq_37998320的博客 1391

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LeetCode-569、员工薪水中位数,571、给定数字的频率查询中位数

来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problemset/database/ 文章目录SQL结构:569. 员工薪水中位数(困难)SQL结构:571. 给定数字的频率查询中位数(困难) SQL结构: Create table If Not Exists Employee (Id int, Company varchar(255), Salary int) Truncate table Employee insert into Employee (Id, .

一个写湿的程序猿 900

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SQL,力扣题目569,员工薪水中位数

2、中位数字段升序和降序的排名相同或者差值为1。id 是该表的主键列(具有唯一值的列)。编写解决方案,找出每个公司的工资中位数。该表的每一行表示公司和一名员工的工资。2、找出中位数所在行,列出结果字段。1、CTE表达式 + 排名函数。

m0_59659684的博客 683

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

LeetCode--569. 员工薪水中位数

建表 drop table if EXISTS employee; create table employee ( Id int primary key auto_increment, Company char, Salary DECIMAL ); insert into employee values(1, 'A', 2341); insert into employee values(null, 'A', 341); insert into employee values(null, 'A', 15).

WGS. 2827

【LeetCode-SQL】569. 员工薪水中位数

目录一、题目二、解决1、窗口函数2、自关联后分组筛选三、参考 一、题目 表: Employee +--------------+---------+ | Column Name | Type | +--------------+---------+ | id | int | | company | varchar | | salary | int | +--------------+---------+ Id是该表的主键列。 该表的每一行表示

HeavenDan的博客 1746

569. 员工薪水中位数

Employee 表包含所有员工。Employee 表有三列:员工Id,公司名和薪水。 Id Company Salary 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 134 13 C 1345 14 C 2645 15 C 2645 16 C 2652 17 C 65 请编

JF823255922的博客 440

Leetcode 569. 员工薪水中位数

先在with中统计每个公司的员工数量,然后使用窗口函数计算每个公司按salary升序排列的行号,然后判断每一个记录是不是中位数记录,最后筛选即可。id 是该表的主键列(具有唯一值的列)。编写解决方案,找出每个公司的工资中位数。该表的每一行表示公司和一名员工的工资。以 任意顺序 返回结果表。表: Employee。请参考思路部分和注释。

m0_51437455的博客 370

LeetCode-569. 员工薪水中位数

Employee 表包含所有员工。Employee 表有三列:员工Id,公司名和薪水。 +-----+------------+--------+ |Id | Company | Salary | +-----+------------+--------+ |1 | A | 2341 | |2 | A | 341 | |3 ...

Hello_JavaScript的博客 646

【力扣 | SQL题 | 每日3题】力扣2988,569,1132,1158

action 列的类型是 ENUM,可能的值为 ('view', 'like', 'reaction', 'comment', 'report', 'share')。2019-07-04 的垃圾广告移除率是 50%,因为有两张帖子被报告为垃圾广告,但只有一个得到移除。编写解决方案,统计在被报告为垃圾广告的帖子中,被移除的帖子的每日平均占比,(buyer_id,seller_id)是 User 表的外键。这张表的主键是 post_id(具有唯一值的列)。item_id 是此表的主键(具有唯一值的列)。

2301_80912559的博客 1241

LeetCode MySQL 569. 员工薪水中位数(over窗口函数)

文章目录1. 题目2. 解题 1. 题目 Employee 表包含所有员工。Employee 表有三列:员工Id,公司名和薪水。 +-----+------------+--------+ |Id | Company | Salary | +-----+------------+--------+ |1 | A | 2341 | |2 | A | 341 | |3 | A | 15 | |4 | A

Michael是个半路程序员 1266

Leetcode力扣 MySQL数据库 569.员工薪水中位数

Leetcode力扣 MySQL数据库 569.员工薪水中位数

m0_46458212的博客 295

LeetCode-569. 员工薪水中位数,知识点:组内排序,获取指定列数据。

Employee 表包含所有员工。Employee 表有三列:员工Id,公司名和薪水。 +-----+------------+--------+ |Id | Company | Salary | +-----+------------+--------+ |1 | A | 2341 | |2 | A | 341 | |3 ...

Hello_JavaScript的博客 1389

mysql 力扣,569.员工薪水中位数

569.员工薪水中位数 https://leetcode-cn.com/problems/median-employee-salary/ 参考答案 # 先组内排序,命名为sc,这里用了库函数,也可以自己写 #这题的中位数是偶数个就是中间两个,奇数个就是中间一个,(题目要求) #然后看where子句,三个分别是每个公司和如果是奇数个就拿中间一个,偶数个就拿个数除以2的,偶数个就拿个数除以2加1的 #然后根据公司和组内排名就把中无数拿出来了。 with sc as (select *,row_nu

xz的博客 540
上一篇: 什么是单元测试?为什么要做?
下一篇: 终于把Python网站开发库大全整理完了,建议收藏!
编程IT圈
博客等级 码龄6年 1130粉丝 544原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值