SQL Exercise: Display all information with specified conditions
SQL Boolean Operators: Exercise-1 with Solution.
From the following table, write a SQL query to locate the details of customers with grade values above 100. Return customer_id, cust_name, city, grade, and salesman_id.
Sample table: customer
customer_id | cust_name | city | grade | salesman_id -------------+----------------+------------+-------+------------- 3002 | Nick Rimando | New York | 100 | 5001 3007 | Brad Davis | New York | 200 | 5001 3005 | Graham Zusi | California | 200 | 5002 3008 | Julian Green | London | 300 | 5002 3004 | Fabian Johnson | Paris | 300 | 5006 3009 | Geoff Cameron | Berlin | 100 | 5003 3003 | Jozy Altidor | Moscow | 200 | 5007 3001 | Brad Guzan | London | | 5005
Sample Solution :
-- This query selects all columns from the 'customer' table.
SELECT *
-- Specifies the table from which to retrieve the data (in this case, 'customer').
FROM customer
-- Filters the rows to only include those where the 'grade' column has a value greater than 100.
WHERE grade > 100;
Output of the Query:
customer_id cust_name city grade salesman_id 3007 Brad Davis New York 200 5001 3005 Graham Zusi California 200 5002 3008 Julian Green London 300 5002 3004 Fabian Johnson Paris 300 5006 3003 Jozy Altidor Moscow 200 5007
Code Explanation:
The said SQL query that is selecting all columns (*) from the 'customer' table where the value of the "grade" column is greater than 100. The query returns all rows from the 'customer' table whose "grade" column is greater than 100.
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: SQL Boolean and Relational Operators Exercises Home
Next SQL Exercise: Information using AND operator with given conditions.
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-1.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics