Medium sql

T-SQL subquery above average #72

Problem

SQL Server: T-SQL subquery above average #72. Write T-SQL against the sample schema.

Hints
  • Use TOP instead of LIMIT
  • ROW_NUMBER() OVER (...)

Your solution

TestStatusDetails
Ready — edit the code above and click Run or Submit.

Solution

-- SQL Server sample schema
CREATE TABLE Departments (Id INT PRIMARY KEY, Name NVARCHAR(100));
CREATE TABLE Employees (Id INT PRIMARY KEY, Name NVARCHAR(100), Salary INT, DeptId INT, Hired DATE);
INSERT INTO Departments VALUES (1,'Engineering'),(2,'Sales');
INSERT INTO Employees VALUES (1,'Alice',90000,1,'2020-01-15'),(2,'Bob',75000,1,'2021-03-01'),(3,'Carol',82000,2,'2019-06-20'),(4,'Dan',68000,2,'2022-11-05');
SELECT Name, Salary FROM Employees
WHERE Salary > (SELECT AVG(Salary) FROM Employees);

Try solving on your own first, then reveal the official answer.

Explanation

T-SQL: TOP, IDENTITY, DATETIME2, CREATE OR ALTER, window functions — common in .NET/SQL Server interviews.

Discussion

0

Sign in to join the discussion.

No discussions yet — ask the first question!

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details