Home > database >  SQL problem
SQL problem

Time:10-01

Please answer

CodePudding user response:

I myself did out, that's great

CodePudding user response:

 USE tempdb for 
GO
IF OBJECT_ID (' project ') IS NOT NULL
DROP TABLE project
GO
The CREATE TABLE project (
Project_id INT,
Employee_id INT
)
GO
INSERT INTO project VALUES (1, 1)
INSERT INTO project VALUES (1, 2)
INSERT INTO project VALUES (1, 3)
INSERT INTO project VALUES (2, 1)
INSERT INTO project VALUES (2, 4)
GO
IF OBJECT_ID (" employee ") IS NOT NULL
DROP TABLE employee
GO
The CREATE TABLE employee (
Employee_id INT,
[name] NVARCHAR (20),
Experience_years INT
)
GO
INSERT INTO the employee VALUES (1, 'Khaled, 3)
INSERT INTO the employee VALUES (2, 'Ali, 2)
INSERT INTO the employee VALUES (3, "John", 3)
INSERT INTO the employee VALUES (4, 'Doe', 2)
GO
SELECT *
The FROM (
The SELECT Rank () OVER (PARTITION BY p.p roject_id ORDER BY e.e xperience_years DESC) AS rids
, p.p roject_id
, e.e mployee_id
, e. [name]
, e.e xperience_years
FROM the project AS p INNER JOIN the employee AS e ON p.e mployee_id=e.e mployee_id
) AS t
WHERE t.r id=1
/*
Rids project_id employee_id name experience_years
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1 1 1 Khaled 3
1 1 3 John 3
1 2 1 Khaled 3
*/

CodePudding user response:

refer to the second floor of gypsy song response:
 USE tempdb for 
GO
IF OBJECT_ID (' project ') IS NOT NULL
DROP TABLE project
GO
The CREATE TABLE project (
Project_id INT,
Employee_id INT
)
GO
INSERT INTO project VALUES (1, 1)
INSERT INTO project VALUES (1, 2)
INSERT INTO project VALUES (1, 3)
INSERT INTO project VALUES (2, 1)
INSERT INTO project VALUES (2, 4)
GO
IF OBJECT_ID (" employee ") IS NOT NULL
DROP TABLE employee
GO
The CREATE TABLE employee (
Employee_id INT,
[name] NVARCHAR (20),
Experience_years INT
)
GO
INSERT INTO the employee VALUES (1, 'Khaled, 3)
INSERT INTO the employee VALUES (2, 'Ali, 2)
INSERT INTO the employee VALUES (3, "John", 3)
INSERT INTO the employee VALUES (4, 'Doe', 2)
GO
SELECT *
The FROM (
The SELECT Rank () OVER (PARTITION BY p.p roject_id ORDER BY e.e xperience_years DESC) AS rids
, p.p roject_id
, e.e mployee_id
, e. [name]
, e.e xperience_years
FROM the project AS p INNER JOIN the employee AS e ON p.e mployee_id=e.e mployee_id
) AS t
WHERE t.r id=1
/*
Rids project_id employee_id name experience_years
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1 1 1 Khaled 3
1 1 3 John 3
1 2 1 Khaled 3
*/

Thank you, you are using mysql to do

CodePudding user response:

SQL server BBS, of course, is to write SQL server,
But the MySQL, 8.0 or above have the same function

CodePudding user response:

reference 4 floor gypsy song response:
SQL server BBS, of course, is to write SQL server,
But MySQL also, 8.0 or above has the same ranking function

Build table I see you, and I don't like so I ask
  • Related