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

What is the method for SQL to search for the top three

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "what is the method of SQL search in the top three", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "what is the method of SQL search in the top three".

The specific data and SQL are like this.

WITH Employee AS (

SELECT 1 Id, 'joe' Name,70000 SALARY,1 DepartmentId FROM DUAL UNION ALL

SELECT 2 Id, 'Henry' Name,80000 SALARY,2 DepartmentId FROM DUAL UNION ALL

SELECT 3 Id, 'Sam' Name,60000 SALARY,2 DepartmentId FROM DUAL UNION ALL

SELECT 4 Id, 'Max' Name,90000 SALARY,1 DepartmentId FROM DUAL UNION ALL

SELECT 5 Id, 'Janet' Name,69000 SALARY,1 DepartmentId FROM DUAL UNION ALL

SELECT 6 Id, 'Randy' Name,85000 SALARY,1 DepartmentId FROM DUAL

),

Department AS (

SELECT 1 Id, 'IT' Name FROM DUAL UNION ALL

SELECT 2 Id, 'Sales' Name FROM DUAL

)

SELECT T1.namename T2.*

FROM

Department T1

, Employee T2

WHERE T1.ID = T2.DepartmentId

AND 3 >

(

SELECT COUNT (distinct T3.SALARY) RN

FROM Employee T3

WHERE T2.DepartmentId = T3.DepartmentId

AND T2.SALARY < T3.SALARY

)

ORDER BY T2.DEPARTMENTID,T2.SALARY

The above is about the content of this article on "what is the method of searching the top three in SQL". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to 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