Write a query to display all the customers whose ID is 2001 below the salesperson ID of Mc Lyon.
Question
Write a query to display all the customers whose ID is 2001 below the salesperson ID of Mc Lyon.
Solution
Sure, here is a SQL query that would display all the customers whose ID is 2001 and are under the salesperson ID of Mc Lyon.
Please note that the exact query might vary depending on the structure of your database. I'm assuming you have a table named 'customers' with fields 'customer_id' and 'salesperson_id', and a table named 'salespersons' with fields 'salesperson_id' and 'salesperson_name'.
SELECT *
FROM customers
WHERE customer_id = 2001
AND salesperson_id IN (
SELECT salesperson_id
FROM salespersons
WHERE salesperson_name = 'Mc Lyon'
);
This query works in the following way:
- The subquery (the part in brackets) selects the ID of the salesperson named 'Mc Lyon' from the 'salespersons' table.
- The main query then selects all records from the 'customers' table where the 'customer_id' is 2001 and the 'salesperson_id' is the same as the one we found in the subquery.
Similar Questions
From the following tables, create a view named mcustomer to display details of salesmen who are associated with more than one customer. Return all the fields of the salesperson.Sample Table: salesmanSample Table: customerNote: Table names and column names are case-sensitive.Input format :The input tables are already prepopulated, as given in the problem statement.Output format :The output is a view named mcustomer that provides details of salesmen who are associated with more than one customer, including their ID, name, city, and commission as shown below.
select customerid,concat_ws(" ",firstname,lastname) as name,timestampdiff(curdate(),Date_of_Birth,Year) as agefrom customersorder by age,customeridcorrect this
Problem StatementYou are tasked with managing sales data for a company. The data includes information about salesmen, customers, and orders. Write a query to find the name and numbers of all salesmen who had more than one customer.The following table is already created, and the records are inserted into the table.The Sample records are given below Input format :The input records are already prepopulated, as given in the problem statement.Output format :The output should include the Salesman_id, Salesman_Name, and Customer_Count for all salesmen who had more than one customer as shown below.Salesman_id Salesman_Name Customer_Count5 Chris Wilson 2Refer to the sample output for the column headers.
Write a query to display the customer id, customer name, guardian name, reference account holders name of the customers who are referenced / referred by the relation 'NEIGHBOUR'(case-sensitive). Display the records sorted in ascending order based on customer id.
Find the names of the customer that are not referred by the customer with id = 2.Return the result table in any order.The result format is in the following example.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.