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;...
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...
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...
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...
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...
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...
The relational schema for the Academics database is as follows: DEPARTMENT(deptnum, descrip, instname, deptname, state, postcode)...
The relational schema for the Academics database is as follows: DEPARTMENT(deptnum, descrip, instname, deptname, state, postcode) ACADEMIC(acnum, deptnum*, famname, givename, initials, title) PAPER(panum, title) AUTHOR(panum*, acnum*) FIELD(fieldnum, id, title) INTEREST(fieldnum*, acnum*, descrip) Some notes on the Academics database: An academic department belongs to one institution (instname) and often has many academics. An academic only works for one department. Research papers (PAPER) are often authored by several academics, and of course an academic often writes several papers (AUTHOR). A research field...
Sellers would offer _____ for sale as prices decreases and thus the supply curve is ____...
Sellers would offer _____ for sale as prices decreases and thus the supply curve is ____ sloping. Select one: a. less; upward b. more; upwards c. more; downwards d. less; downwards You should decide to go to a movie: Select one: a. If the marginal benefit of the movie exceeds its marginal cost.. b. If your income will allow you to buy a ticket c. because movies are enjoyable d. If the marginal cost of the movie exceeds its marginal...
​Total cost is calculated as _____. Select one: a. ​average fixed cost plus average variable cost...
​Total cost is calculated as _____. Select one: a. ​average fixed cost plus average variable cost b. ​fixed cost plus variable cost c. ​the additional cost of the last unit produced d. ​marginal cost plus variable cost e. ​marginal cost plus fixed cost -------------------------------------------------------------------------------------- ​The law of diminishing marginal returns states that: Select one: a. ​long-run average cost declines as output increases. b. ​if the marginal product is above the average product, the average will rise. c. ​as units of...