Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

SQL Subquery Exercises: Display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York

SQL SUBQUERY: Exercise-22 with Solution

22. From the following table write a SQL query to find all those customers with a higher grade than any customer who belongs to the alphabetically lower than the city New York. Return customer_id, cust_name, city, grade, salesman_id.

Sample table: Customer


Sample Solution:

SELECT *
FROM customer
WHERE grade > ANY
   (SELECT grade
	FROM CUSTOMER
	WHERE  city < 'New York');

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

Explanation:

SQL Subqueries: Display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York.

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York - Duration

Rows:

Query visualization of Display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York - Rows

Cost:

Query visualization of Display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York - Cost

Contribute your code and comments through Disqus.

Previous: From the following tables, write a SQL query to find all those salespeople whose name exist alphabetically after the customer’s name. Return salesman_id, name, city, commission.
Next: From the following table write a SQL query to find all those orders whose order amount greater than at least one of the orders of September 10th 2012. Return ord_no, purch_amt, ord_date, customer_id and salesman_id.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

Ref: https://bit.ly/3y6tpA3