当前位置:网站首页>Group by group and get the first data
Group by group and get the first data
2022-07-24 08:25:00 【The bearer of dark cuisine】
MYSQL GROUP BY
mysql I use sorting to filter , Guarantee grouping 、 After sorting, my first data is the data I want
SELECT a.code ,
a.type AS Class type ,MAX(a.num)
FROM
(
SELECT
*
FROM
cent_ylb_numclass
GROUP BY
CODE,
type
ORDER BY
CODE,
num DESC
) AS a
GROUP BY
`code`ORACLE GROUP BY
oracle Use the windowing function . Access data according to serial number
grammar :
ROW_NUMBER() OVER(PARTITION BY COLUMN1 ORDER BY COLUMN2 [desc])
according to column1 grouping , according to column2 Sort This time we need to code according to the teacher code Grouping , Teacher code ()code) And the number of teacher course groups (count( Course grouping )) null
We need to determine which course a teacher teaches the most
SELECT
localtable. Teacher code as Teacher code ,localtable. Course as grouping
FROM
(SELECT
tablebiao. Teacher code as Teacher code ,
tablebiao. Teacher's name as Teacher's name ,
tablebiao. Course grouping as Course ,
COUNT(tablebiao. Course grouping ) AS num,
row_number () over (
PARTITION BY tablebiao. Teacher code ,
tablebiao. Teacher's name
ORDER BY
tablebiao. Teacher code ,
COUNT(tablebiao. Course grouping ) DESC
) AS rn
FROM
tablebiao
GROUP BY
tablebiao. Teacher code ,
tablebiao. Teacher's name ,
tablebiao. Course grouping
ORDER BY
tablebiao. Teacher code ,
COUNT(tablebiao. Course grouping ) DESC
) localtable
WHERE
localtable.rn = 1
If there is a better implementation method , Or for guidance, please contact wechat c243126035
边栏推荐
- Saining Techtalk attack and defense drill: attack combination fist "stable, accurate and ruthless" penetration
- Stack / heap / queue question brushing (Part 2)
- nacos报错: ERROR Nacos failed to start, please see D:\nacos\logs\nacos.log for more details.
- Overseas media, domestic we media, media publicity
- FPGA integrated project - image edge detection system
- FPGA综合项目——图像边缘检测系统
- You can't access this shared folder because your organization's security policies prevent unauthenticated guests from accessing it. These policies can help protect your computer from unsafe or malicio
- [tools] a few lines of code can realize complex excel import and export tool classes, which is really strong!!!
- 2022.7.11全盘题解
- Draw a circular radar chart with canvas
猜你喜欢

JMX Console 未授权访问漏洞

Wechat applet subscription message development process
![[matlab] (IV) application of MATLAB in linear algebra](/img/c8/97fddb4105008990173247b1b4a155.png)
[matlab] (IV) application of MATLAB in linear algebra

From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run

Avoid pitfalls and stay away from PUA in the workplace. You need to know the common routines and scripts of PUA!

国产“火箭心”人工心脏上市 不同人工心脏有什么区别?

赛宁TechTalk丨攻防演练:攻击组合拳 “稳准狠”渗透

JSON extractor use in JMeter

Brief notes on the key points of distributed system principle introduction

Kotlin higher order function & DSL layout persuasion Guide
随机推荐
SOA and microservice examples
Adaptive problem of img aspect ratio scaling in flex layout in Safari
学习-用do…while循环按公式e=1+1/1!+1/2!+1/3!+…+1/n!计算 e 的值(精度为 1e-6)
Use of animation expert motionlayout layout
Alibaba cloud deploys SSL certificates
nacos报错: ERROR Nacos failed to start, please see D:\nacos\logs\nacos.log for more details.
Poj3278 catch the cow
Overseas media, domestic we media, media publicity
Summary of study notes (I)
Wei Xiaoli's "pursuer" is coming
Enterprises love hybrid app development, and applet container technology can improve efficiency by 100%
「题解」带分数
Introduction to wechat authorized login third-party app applet method
[shutter] the shutter doctor reports an error
Cososcreator upgrade gradle version
A Knight‘s Journey题解
[MySQL] 08: aggregate function
[database] complete SQL statement
Private traffic + apps, new opportunities for e-commerce drainage
Wechat applet host environment, applet architecture, concise operation structure