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 =...
1, The following query is called_________ SQL>select e.empno,e.ename, m.ename, m.empno from emp e, emp m where...
1, The following query is called_________ SQL>select e.empno,e.ename, m.ename, m.empno from emp e, emp m where e.mgr = m.empno; cross join outer join Self join Full join Natural Joins 2. Steve wants to write a query to display the employee last name, department name, location id, and city of all employees who earn a commission. He wrote the following query. is it true or false. SELECT e.last_name, d.department_name, d.location_id, l.city FROM employees e, departments d, locations l WHERE e.department_id =...
oDisplay the ProductID for the product that has been sold the most (i.e., that has been...
oDisplay the ProductID for the product that has been sold the most (i.e., that has been sold in the highest quantity). I am trying to run the SQL query on Terada (shown below) and keep getting the same error "cannot nest aggregate operations." Someone please help. SELECT productid FROM soldvia GROUP BY productid HAVING SUM(noofitems) = (SELECT MAX(SUM(noofitems))                          FROM soldvia                          GROUP BY productid);
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...
You query data from emp2 table with below SQL statement: SQL> SELECT *     FROM  emp2; NAME SSN...
You query data from emp2 table with below SQL statement: SQL> SELECT *     FROM  emp2; NAME SSN ------------- ------------------------ Joe 452852452 Mary 444525962 Fred 445212525 Tom 492525252 Lucy   172826152   Now, you query data from emp2 table with below SQL statement again: SQL> SELECT AVG(LENGTH(name)) AS column1, SUM(INSTR(ssn, '%@',2,2)) AS column2 FROM  emp2 WHERE name = INICAP(name); What will be displayed for the output of column1 and column2? A. The value in column1 will be 3.5 and the value in column2 will be...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT