You are a developer for a Microsoft SQL Server database instance used to support a customer service application. You create tables named complaint, customer, and product as follows:CREATE TABLE [dbo].[complaint] ([ComplaintID] [int], [ProductID] [int], [CustomerID] [int], [ComplaintDate] [datetime]);CREATE TABLE [dbo].[customer] ([CustomerID] [int], [CustomerName] [varchar](100), , , , );CREATE TABLE [dbo].[product] ([ProductID] [int], [ProductName] [varchar](100), [SalePrice] [money], [ManufacturerName] [varchar](100));You need to write a query to identify all customers who have complained about products that have an average sales price of 500 or more from September 01, 2011.Which SQL query should you use?SELECT c.CustomerName, AVG(p.SalePrice) AS Sales FROM product p INNER JOIN complaint com ON p.ProductID = com.ProductID INNER JOIN customer c ON com.CustomerID = c.CustomerID WHERE com.ComplaintDate > '09/01/2011' GROUP BY c.CustomerName HAVING AVG(p.SalePrice) >= 500;SELECT c.CustomerName, SUM(p.SalePrice) AS Sales FROM product p INNER JOIN complaint com ON p.ProductID = com.ProductID INNER JOIN customer c ON com.CustomerID = c.CustomerID WHERE com.ComplaintDate > '09/01/2011' AND SUM(p.SalePrice) >= 500 GROUP BY c.CustomerName;SELECT c.CustomerName, AVG(p.SalePrice) AS Sales FROM product p INNER JOIN complaint com ON p.ProductID = com.ProductID INNER JOIN customer c ON com.CustomerID = c.CustomerID WHERE com.ComplaintDate > '09/01/2011' AND AVG(p.SalePrice) >= 500 GROUP BY c.CustomerName;None of the above
Question
You are a developer for a Microsoft SQL Server database instance used to support a customer service application. You create tables named complaint, customer, and product as follows:CREATE TABLE [dbo].[complaint] ([ComplaintID] [int], [ProductID] [int], [CustomerID] [int], [ComplaintDate] [datetime]);CREATE TABLE [dbo].[customer] ([CustomerID] [int], [CustomerName] varchar, , , , );CREATE TABLE [dbo].[product] ([ProductID] [int], [ProductName] varchar, [SalePrice] [money], [ManufacturerName] varchar);You need to write a query to identify all customers who have complained about products that have an average sales price of 500 or more from September 01, 2011.Which SQL query should you use?SELECT c.CustomerName, AVG(p.SalePrice) AS Sales FROM product p INNER JOIN complaint com ON p.ProductID = com.ProductID INNER JOIN customer c ON com.CustomerID = c.CustomerID WHERE com.ComplaintDate > '09/01/2011' GROUP BY c.CustomerName HAVING AVG(p.SalePrice) >= 500;SELECT c.CustomerName, SUM(p.SalePrice) AS Sales FROM product p INNER JOIN complaint com ON p.ProductID = com.ProductID INNER JOIN customer c ON com.CustomerID = c.CustomerID WHERE com.ComplaintDate > '09/01/2011' AND SUM(p.SalePrice) >= 500 GROUP BY c.CustomerName;SELECT c.CustomerName, AVG(p.SalePrice) AS Sales FROM product p INNER JOIN complaint com ON p.ProductID = com.ProductID INNER JOIN customer c ON com.CustomerID = c.CustomerID WHERE com.ComplaintDate > '09/01/2011' AND AVG(p.SalePrice) >= 500 GROUP BY c.CustomerName;None of the above
Solution
The correct SQL query to use would be:
SELECT c.CustomerName, AVG(p.SalePrice) AS Sales
FROM product p
INNER JOIN complaint com ON p.ProductID = com.ProductID
INNER JOIN customer c ON com.CustomerID = c.CustomerID
WHERE com.ComplaintDate > '09/01/2011'
GROUP BY c.CustomerName
HAVING AVG(p.SalePrice) >= 500;
This query works by joining the product, complaint, and customer tables based on the ProductID and CustomerID. It then filters the results to only include complaints made after September 1, 2011. The results are grouped by the customer's name, and the HAVING clause is used to only include groups where the average sale price of the products is 500 or more.
Similar Questions
What do you mean by table? How can you create table in SQL?
i. Create a database called orderproc_db for an Order processing company usingMySQL.ii. Replace the data types in the tables given below with MySQL Compatible format.iii. Using the orderproc_db database, create the following tables.CUSTOMER (custno: INT, cname: STRING, city: STRING)ORDE (orderno: INT, odate: DATE, custno: INT, ord_amt: INT)ITEM (itemno: INT, unit_price: INT)ORDE_ITEM (orderno: INT, itemno: INT, qty: INT)WAREHOUSE (warehouseno: INT, city: STRING)SHIPMENT (orderno: INT, warehouseno: INT, ship_date: DATE)iv. Identify the primary key and define primary key constrains for the table.v. Identify the foreign keys and enforce referential integrity for the tables.vi. Describe the structures of the tables you have created above.vii. Insert the records to the tables. Records are available as text files with the respectivetable names in a folder called “Tables” on your desktop. You need to properly formatthese records before inserting into the tables.viii. List all customers from Batticaloa.ix. Propose an alternative method to execute the above question (viii).x. Select all customers who are from Batticaloa or Jaffna.xi. How many customers are there in Colombo?xii. List the customer’s name ending with the letters “na”.xiii. List all the order amount above 50000.xiv. List all customers name who made order above 50000.xv. List all customers name who have at least one warehouse in their city.xvi. How many different cities are there in the customer table.xvii. How many warehouses are there in Colombo?.xviii. How do you check all order dates are less than or equal to shipping dates?xix. List all the order number, order date, customer number and order amount where all theshipment made from Colombo warehouses.
Consider the below tables:Promotions TableColumn NameDatatypeConstraintPromo_idNumberPKPromo_nameVarchar Promo_begin_dateDate Promo_end_dateDate Sales TableColumn NameDatatypeConstraintPromo_idNumberFKCust_idNumberFKTime_idDate Customer TableColumn NameDatatypeConstraintcust_idNumberPKcust_nameVarchar The Below query will generate a report showing the promo name along with the customer name for all products that were sold during their promo campaign and before 30th October 2007.SELECT promo_name,cust_name FROM promotions p JOIN sales s ON(time_id BETWEEN promo_begin_date AND promo_end_date) JOIN customer c ON (s.cust_id = c.cust_id) AND time_id < '30-oct-2007'; Which statement is true regarding the above query? Select one:a.It produces an error because the join order of the tables is incorrect.b.It produces an error because equijoin and nonequijoin conditions cannot be used in the samec.It executes successfully but does not give the required result.d.It executes successfully and gives the required result.
onsider the following relations to answer Question.Manufacturer (ManufacturerId, MName, DateOfBirth, Gender MAddress, AwardWon)Part (PartNo, PName, Description, ManufacturerId)Order (PartNo, OrderNo, OrderQuantity, OrderedDate, CustomerId)Customer (CustomerId, Email, CName, CAddress, Job, TotalNoOfCustomers)Most suitable data type (s) for OrderNo, OrderQuantity, OrderedDate in Order relation respectively is/are:Select one:a.Number, Number, Dateb.Text, Text, Datec.Number, Number, Numberd.Number, Text, Datee.Text, Text, Text
You have a Microsoft SQL Server database that contains tables named Customers and Orders. The tables are related by a column named CustomerID. You need to create a query that meets the following requirements:1. Returns the CustomerName for all customers and the OrderDate for any orders that they have placed. 2. Results must include customers who have not placed any orders. Which Transact-SQL query should you use?
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.