Top 3 Earners
EasySQLDatabaseSorting
Description
Write a SQL query to return the name and salary of the three highest-paid employees, ordered by salary descending. **Output columns (in order):** name, salary
Table:
employees| Column | Type |
|---|---|
| id | INT |
| name | TEXT |
| salary | INT |
Examples
Input:
CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1,'A',100),(2,'B',300),(3,'C',200),(4,'D',400);Output:
D|400
B|300
C|200Explanation:
Ordering by pay from high to low and keeping the first three yields the top earners.
Input:
CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1,'A',50),(2,'B',60);Output:
B|60
A|50Explanation:
Ordering by pay from high to low and keeping the first three yields the top earners.
Input:
CREATE TABLE employees (id INT, name TEXT, salary INT); INSERT INTO employees VALUES (1,'Solo',999);Output:
Solo|999Explanation:
Ordering by pay from high to low and keeping the first three yields the top earners.
Constraints
- •
Use standard SQL (SQLite).