SQL Exercise: Using AND operator with a specified condition
SQL Boolean Operator Statement: Exercise-7 with Solution.
From the following table, write a SQL query to find the details of those salespeople whose commissions range from 0.10 to0.12. Return salesman_id, name, city, and commission.
Sample table : salesman
salesman_id | name | city | commission -------------+------------+----------+------------ 5001 | James Hoog | New York | 0.15 5002 | Nail Knite | Paris | 0.13 5005 | Pit Alex | London | 0.11 5006 | Mc Lyon | Paris | 0.14 5007 | Paul Adam | Rome | 0.13 5003 | Lauson Hen | San Jose | 0.12
Sample Solution :
-- This query selects specific columns 'salesman_id', 'name', 'city', and 'commission' from the 'salesman' table.
SELECT salesman_id, name, city, commission
-- Specifies the table from which to retrieve the data (in this case, 'salesman').
FROM salesman
-- Filters the rows to only include those where the 'commission' column is greater than 0.10 and less than 0.12.
WHERE (commission > 0.10 AND commission < 0.12);
Output of the Query:
salesman_id name city commission 5005 Pit Alex London 0.11
Code Explanation:
The given SQL query that is selecting specific columns "salesman_id, name, city, commission" from the 'salesman' table where the value of the "commission" column is greater than 0.10 and less than 0.12.
The query will return all rows from the ‘salesman’ table where the commission is greater than 0.10 and less than 0.12 along with the selected columns.
Relational Algebra Expression:
Relational Algebra Tree:
Explanation :
Visual presentation:
Practice Online
Query Visualization:
Duration:
Rows:
Cost:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Using AND, OR operator with a specified condition.
Next SQL Exercise: Using NOT, AND operators with specified condition.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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/sql-boolean-operator-exercise-7.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics