当前位置:网站首页>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
边栏推荐
- Vidar-Team战队专访:AS WE DO, AS YOU KNOW.
- 图的认识与存储
- Enterprises love hybrid app development, and applet container technology can improve efficiency by 100%
- Assembly | screen display numbers
- Advantages and disadvantages of redis and ZK implementing distributed locks
- Look at the most influential infrastructure m-dao of Web3 through the current situation of Dao
- [matlab] (III) application of MATLAB in Higher Mathematics
- Draw a circular radar chart with canvas
- Musk responded that the brain has been uploaded to the cloud: already did it!
- [internationalization] decimal point and comma of application development
猜你喜欢

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

As skillfully uses idea annotation to improve collaboration / development efficiency

Introduction of some functions or methods in DGL Library
![[Yum] configuration and use of Yum source](/img/38/16a910d9a038d513e0b0a54ba81b93.jpg)
[Yum] configuration and use of Yum source

Wechat payment V3 version of openresty implementation and pit avoidance Guide (service side)
![[wechat applet development (III)] realize the stacking and sliding of cards](/img/6c/4ebd60a2106b56b8bf3a6bf17d11f9.png)
[wechat applet development (III)] realize the stacking and sliding of cards

Svg from entry to regret, why not learn it earlier (graphic version)

Mysql database advanced

Read and understand move2earn project - move
![[redis] how much do you know about bloom filter and cuckoo filter?](/img/f0/8bcbe82bd6d412e68d85450f5894e3.png)
[redis] how much do you know about bloom filter and cuckoo filter?
随机推荐
Use of animation expert motionlayout layout
P1135 strange elevator problem solution
[wechat applet development (II)] custom navigation bar
Okaleido tiger NFT is about to log in to binance NFT platform, and the era of NFT rights and interests is about to start
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
Ansible automatic operation and maintenance
[matlab] (IV) application of MATLAB in linear algebra
SVG 从入门到后悔,怎么不早点学起来(图解版)
2022.7.11 overall solution
Dao race track is booming. What are the advantages of m-dao?
Why does the metauniverse need NFT?
Is it safe to open an account online in Beijing
P1739表达式括号匹配题解
[wechat applet development] (II) wechat native bottom tabbar configuration
【JDBC】JDBC经典面试题,持续更新中......
dba
[shutter] the shutter doctor reports an error
Look at the most influential infrastructure m-dao of Web3 through the current situation of Dao
[multithreading] five communication modes between multithreads
Go: how to gracefully time out