Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQL's name and id with the most repeated queries

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will bring you an article about the name and id with the most repeated queries in SQL. The editor thinks it's pretty good, so I'll share it for you as a reference. Let's follow the editor and have a look.

The structure of the table is as follows:

Requirements: id and name name may be repeated multiple times. But there is only one ID, and you need to find the name and ID that are repeated the most. There are probably several names that are repeated the most, each with a different ID.

SELECT t.id,t.name,a.nu FROM t

LEFT JOIN

(SELECT id,NAME,COUNT () AS nu FROM t GROUP BY NAME) an ON t.name=a.name

JOIN

(SELECT id,NAME,COUNT () AS num FROM t GROUP BY NAME ORDER BY num DESC LIMIT 1) c

WHERE a.nu=c.num

The above are the names with the most repeated queries in SQL and the details of id, and the details of usage still need to be used in hands-on experiments to be understood. If you want to know more, you are welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report