SQL Challenges-1: Find those salespersons whose commission is less than ten thousand
SQL Challenges-1: Exercise-26 with Solution
From the following table, write a SQL query to find those salespersons whose commission is less than ten thousand. Return salesperson name, commission.
Input:
Table: salemast
Structure:
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
salesman_id | int(11) | YES | |||
salesman_name | varchar(255) | YES | |||
yearly_sale | int(11) | YES |
Data:
salesman_id | salesman_name | yearly_sale |
---|---|---|
101 | Adam | 250000 |
103 | Mark | 100000 |
104 | Liam | 200000 |
102 | Evan | 150000 |
105 | Blake | 275000 |
106 | Noah | 50000 |
Table: commision
Structure:
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
salesman_id | int(11) | YES | |||
commision_amt | int(11) | YES |
Data:
salesman_id | commision_amt |
---|---|
101 | 10000 |
103 | 4000 |
104 | 8000 |
102 | 6000 |
105 | 11000 |
Sample Solution:
SQL Code(MySQL):
CREATE TABLE salemast(salesman_id int, salesman_name varchar(255), yearly_sale int);
INSERT INTO salemast VALUES (101, 'Adam', 250000);
INSERT INTO salemast VALUES (103, 'Mark', 100000);
INSERT INTO salemast VALUES (104, 'Liam', 200000);
INSERT INTO salemast VALUES (102, 'Evan', 150000);
INSERT INTO salemast VALUES (105, 'Blake', 275000);
INSERT INTO salemast VALUES (106, 'Noah', 50000);
SELECT * FROM salemast;
CREATE TABLE commision (salesman_id int, commision_amt int);
INSERT INTO commision VALUES (101, 10000);
INSERT INTO commision VALUES (103, 4000);
INSERT INTO commision VALUES (104, 8000);
INSERT INTO commision VALUES (102, 6000);
INSERT INTO commision VALUES (105, 11000);
SELECT * FROM commision;
SELECT s.salesman_name,c.commision_amt
FROM salemast s LEFT JOIN
commision c
ON s.salesman_id=c.salesman_id
WHERE c.commision_amt<10000;
Sample Output:
salesman_name|commision_amt| -------------|-------------| Mark | 4000| Liam | 8000| Evan | 6000|
SQL Code Editor:
Contribute your code and comments through Disqus.
Previous: Find the first login date for each customer.
Next: Distributor who purchased all types of item from the company.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/sql-exercises/challenges-1/sql-challenges-1-exercise-26.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics