Question

Which query lists all products with a total quantity sold less than the average quantity sold?...

Which query lists all products with a total quantity sold less than the average quantity sold?

Select one:

a.
SELECT P_CODE, SUM(LINE_UNITS) AS TOTALUNITS
FROM LINE
GROUP BY P_CODE
HAVING SUM(LINE_UNITS) < AVG(LINE_UNITS);

b.
SELECT P_CODE, AVG(LINE_UNITS) AS TOTALUNITS
FROM LINE
GROUP BY P_CODE
HAVING AVG(LINE_UNITS) < (SELECT AVG(LINE_UNITS) FROM LINE);

c.
SELECT P_CODE, SUM(LINE_UNITS) AS TOTALUNITS
FROM LINE
GROUP BY P_CODE
HAVING SUM(LINE_UNITS) < (SELECT AVG(LINE_UNITS) FROM LINE);

d.
SELECT P_CODE, SUM(LINE_UNITS) AS TOTALUNITS
FROM LINE
GROUP BY P_CODE
HAVING SUM(LINE_UNITS) > (SELECT SUM(LINE_UNITS) FROM LINE);

Which query returns the number of different vendors in the PRODUCT table?

Select one:

a.
SELECT DISTINCT COUNT(V_CODE)

FROM PRODUCT;

b.
SELECT COUNT(V_CODE)

FROM PRODUCT;

c.
SELECT COUNT(DISTINCT V_CODE)

FROM PRODUCT;

d.
SELECT DISTINCT(V_CODE)

FROM PRODUCT;

Which query returns the number of products in the inventory supplied by each vendor and limit the listing to products whose prices average greater than equal $100?

Select one:

a.
SELECT V_CODE, COUNT(P_CODE) AS NUMPRODS, AVG(P_PRICE) AS AVGPRICE
FROM PRODUCT
WHERE AVG(P_PRICE) >= 100
GROUP BY V_CODE
ORDER BY V_CODE;

b.
SELECT V_CODE, COUNT(P_CODE) AS NUMPRODS
FROM PRODUCT
GROUP BY V_CODE
HAVING AVG(P_PRICE) >= 100
ORDER BY V_CODE;

c.
SELECT V_CODE, COUNT(P_CODE) AS NUMPRODS
FROM PRODUCT
WHERE AVG(P_PRICE) >= 100
ORDER BY V_CODE;

d.
SELECT V_CODE, COUNT(P_CODE) AS NUMPRODS, AVG(P_PRICE) AS AVGPRICE
FROM PRODUCT
GROUP BY V_CODE
WHERE AVG(P_PRICE) >= 100
ORDER BY V_CODE;

Aggregate functions ignore nulls when performing calculations, but the GROUP BY clause includes nulls and considers all of the nulls to be the same when forming collections.

Select one:

True

False

Unlike ORDER BY clause, the order of attributes in GROUP BY clause does not matter.

Select one:

True

False

in SQL language

Homework Answers

Answer #1

1. OPTION (C)

Explanation: We need to select pcode whose total quanity sold is less than average of quantiy sold. So, first we find average of quantity sold SELECT AVG(LINE_QTY) FROM LINE and then compare it with sum of quantity sold by each pcode using groupby command.

2. OPTION (C)

Explanation: This is proper syntax of using DISTINCT with COUNT().

3. OPTION (B)

Explanation: firstly compute average for each product using GROUP BY and then you need to set limit . Instinct says to use WHERE clause but remember GROUP BY is mostly used with HAVING clause.

4. True

Explanation: All Aggregate functions except COUNT(*) and GROUPBY ignore nulls when performing calculations and groupby considers all of the nulls to be the same when forming collections. which means group by will also return group where all entity is null.

5. True

Explanation: order doesn't matter in GROUP BY CLAUSE.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A(n) _____ is a query that is embedded (or nested) inside another query. Select one: a....
A(n) _____ is a query that is embedded (or nested) inside another query. Select one: a. operator b. subquery c. alias d. view If a subquery returns list of values, which operator can be used in the outer query predicate? Select one: a. > b. < c. IN d. = Which query returns a list of all products with a price greater than or equal to the average product price? Select one: a. SELECT P_CODE,MAX(AVG(P_PRICE)) FROM PRODUCT GROUP BY P_CODE;...
1) In which clause of a query can a subquery not be used? (Choose two.) 2)...
1) In which clause of a query can a subquery not be used? (Choose two.) 2) The ORDER BY clause is allowed in an inline view true or false 3) the order by clause is not allowed in subqueries true or false 4) The operators IN and EXISTS are somewhat equivalent true or false 5) this Oracle error message? ORA-01427: single- row subquery returns more than one row >= = IN <= 6) SELECT 'TRUE' FROM dual WHERE 6 =...
PS8 JULY 1. Log on to your Oracle ApEx account. Navigate to SQL Workshop à SQL...
PS8 JULY 1. Log on to your Oracle ApEx account. Navigate to SQL Workshop à SQL Scripts Create a SQL script called update_demo_orders that contains these update statements: update demo_orders set order_total = 200 where customer_id = 1; update demo_orders set order_total = 15 where customer_id = 2; update demo_orders set order_total = 12 where customer_id = 3; update demo_orders set order_total = 22 where customer_id = 4; update demo_orders set order_total = 32 where customer_id = 5; update demo_orders...
How many customers placed orders between 1-Apr-03 and 31-May-03? COUNT 12 a.    SELECT COUNT(DISTINCT order_no)...
How many customers placed orders between 1-Apr-03 and 31-May-03? COUNT 12 a.    SELECT COUNT(DISTINCT order_no) AS count       FROM Orders       WHERE order_date BETWEEN '1-APR-03' AND '31-May-03'; b.    SELECT COUNT(DISTINCT order_no) AS count       FROM Orders       WHERE order_date BETWEEN '4/1/03' AND '5/31/03'; c.    a and b are correct d.    a and b are incorrect Question 2 (2 points) . Find product no. , brand and unit price of the products whose unit price is greater than the unit...
1. Write a SELECT statement to count SKUs for each department, i.e., a table of two...
1. Write a SELECT statement to count SKUs for each department, i.e., a table of two columns, departments and their SKU counts. use cape_codd; select department, count(*) from sku_data group by department ; 2. List buyers who is responsible for at least two SKUs, in three columns, department, buyer, sku count. Sort buyers by their department names in ascending order. select department, buyer, count(sku) from sku_data group by buyer ; 3. Write a SQL statement which returns all the orders....
Customers ID Name Street City Zip email 1 Emily 101 Anza St San Francisco 94118 2...
Customers ID Name Street City Zip email 1 Emily 101 Anza St San Francisco 94118 2 Amy 1 Houston Ave New York 12111 3 John 29 Sunset Blvd Los Angeles 45643 4 Pam 800 Market St San Francisco 94080 5 Sue 400 Muir Ave Redwood City 94598 6 Chris 987 A Ave New York 13111 7 Todd 788 Harrison St San Francisco 94117 Products ID Product_name Price Quantity 1 Metal pen 5.99 20 2 Surge protector 25.99 0 3 pencil...
Class-In Assignment 3: Chapters 4&5 How to retrieve data from two or more tables Exercises 1....
Class-In Assignment 3: Chapters 4&5 How to retrieve data from two or more tables Exercises 1. Write a SELECT statement that returns all columns from the Vendors table inner-joined with all columns from the Invoices table. 2. Write a SELECT statement that returns four columns: vendor_name vendor_name from the Vendors table invoice_number invoice_number from the Invoices table invoice_date invoice_date from the Invoices table balance_due invoice_total minus payment_total minus credit_total from the Invoices table The result set should have one row...
Use the following tables to answer Q5 and Q6. Tourist (tno, Name, phone, age,loc) Vehicle (Vno,...
Use the following tables to answer Q5 and Q6. Tourist (tno, Name, phone, age,loc) Vehicle (Vno, model, mileage, owner_name, owner_ph)) Rented (tno, Vno) 5. (i)Write an SQL query, to create the table vehicle with following constraints: Vno should begin with second letter ‘v’; Models are one among Thar, X3. Mileage should be above 18 and below 25. No two records can have same phone (ii) Write an SQL query to retrieve the name of the owner who does owns X3...
Translating MongoDB Queries to SQL - WILL UPVOTE!! 1. Write the equivalent sql queries for all...
Translating MongoDB Queries to SQL - WILL UPVOTE!! 1. Write the equivalent sql queries for all mongoDB queries. The following is an example of what you are asked to do. Assume the collection name is the table name in an sql database. Example: MongoDB Query: db.zips.aggregate([ {$match: {state: "MO"}}, {$group: {_id: "$city", totalPop: {$sum: "$pop"}}}, {$sort: {totalPop: -1}}, {$limit: 10} ]) SQL Result: Select city, SUM(pop) AS "totalPop" From zips Where state = "MO" Group By city Order By SUM(pop)...
Question text Which of the following best describes constrained optimization problem? Select one: a. A constrained...
Question text Which of the following best describes constrained optimization problem? Select one: a. A constrained optimization problem is an optimization problem that maintains a priority queue of variables, where the weight of a variable is the number of conflicts in which it participates. b. A constrained optimization problem is an optimization problem that also has hard constraints specifying which variable assignments are possible. The aim is to find an optimal assignment that satisfies the hard constraints. c. A constrained...