Question

In: Computer Science

Subject DataBase/MySQL What is wrong with this statement? SELECT vendor_id, (SELECT vendor_name FROM vendors), avg(invoice_total) FROM...

Subject DataBase/MySQL

What is wrong with this statement?

SELECT vendor_id, (SELECT vendor_name FROM vendors), avg(invoice_total)
FROM invoices
GROUP BY vendor_id;

Select one:

a. The subquery returns more than 1 row.

b. You need a JOIN ON clause to pull from multiple tables.

c. You cannot have a subquery in the SELECT statement.

d. The result is a Cartesian Product.

e. There is nothing wrong with this statement.

What is wrong with this statement?

SELECT vendor_name, avg(invoice_total) AS 'Invoice Total'
FROM vendors v
JOIN invoices i ON v.vendor_id = i.vendor_id

Select one:

a. You are missing the GROUP BY clause.

b. Nothing, this statement runs correctly.

c. The JOIN ON clause is incorrect.

d. Invoices should also be in the FROM clause.

e. You are using single quotes instead of double quotes.

- TIA

Solutions

Expert Solution

Query1 -

SELECT vendor_id, (SELECT vendor_name FROM vendors), avg(invoice_total)

FROM invoices

GROUP BY vendor_id;

Answer - correct option c

Explanation :

Vendor_id and vendor_name belongs to same table so there is no need of subquery in SELECT clause.

It is required to JOIN two tables on common attribute or use vendor table in FROM clause. Group BY will arrange values according to vendor_id in ascending order by default.

SELECT vendor_id, vendor_name , avg(invoice_total)

FROM invoices, vendors

GROUP BY vendor_id;

Query 2 -

SELECT vendor_name, avg(invoice_total) AS 'Invoice Total'

FROM vendors v

JOIN invoices i ON v.vendor_id = i.vendor_id

Answer - correct option c

Explanation :

This query will fetch vendor name form table vendors as v

average of total invoice renaming the column as Invoice Total

JOIN will join the table invoice and vendors on id. But we have to join invoice with vendors.

SELECT vendor_name, avg(invoice_total) AS 'Invoice Total'

FROM vendors v

JOIN invoices i ON i.vendor_id = v.vendor_id

So this query will give vendor name and invoice total in the output.


Related Solutions

Subject - DataBase / MySQL * Which of the following is not correct about the statement...
Subject - DataBase / MySQL * Which of the following is not correct about the statement provided? SELECT Customer#, FirstName, LastName FROM Customers C JOIN Orders O ON C.Customer# = O.Customer# JOIN OrderItems OI ON O.Order# = OI.Order# JOIN Books B ON OI.ISBN = B.ISBN WHERE Category = 'Fitness' AND Category = 'Computers'; Select one: a. Joins the OrderItems table to the Books table using the field ISBN b. All of these are correct c. Joins the Customer table to...
MySQL: What are the various SELECT statement clauses? Which ones are necessary and optional? How are...
MySQL: What are the various SELECT statement clauses? Which ones are necessary and optional? How are the results filtered using COMPARISON and LOGICAL OPERATORS? Give one of these operators examples. Describe how parentheses can influence a query result.
PHP, JAVASCRIPT, MYSQL below is what I have. Can fill in the details for the database...
PHP, JAVASCRIPT, MYSQL below is what I have. Can fill in the details for the database 5. “Login to DB”, “Logout DB”, sub-menus of “File” 5.1 _____ When the user selects “Login to DB”, a window should popup asking the user to enter login and password. Your program should verify the login and password against the DV_User table in the datamining database. A corresponding message should be shown in the message area when the login failed or successful. If it...
Please state each statement is right or wrong and explain in detail. 1. Subject A has...
Please state each statement is right or wrong and explain in detail. 1. Subject A has the following values: Minute ventilation = 7 liters/minute, Respiratory frequency = 16 Br/minute, PaCO2 = 35 mm Hg, PECO2 = 27 mm Hg. Identify whether each of the following are correct or incorrect. a. VT = 2.3 liters b. VD/VT = 0.23 c. the alveolar volume is 77% of the Vt d. VA = 5.4 liters/minute 2. Subject B is a 5 foot tall...
the mysql lyrics database is provided below 1.)What is a primary key used for? Can you...
the mysql lyrics database is provided below 1.)What is a primary key used for? Can you give me an example of a primary key in the Lyrics database? 2.)What is the purpose of doing a join between two tables. Ex. Why would I ever want to join the Tracks and Titles tables together? 3.)Why is isolation important in database design? DROP TABLES IF EXISTS Artists,Genre, Members, Titles, Tracks,SalesPeople,Studios,XrefArtistsMembers; DROP TABLES IF EXISTS Authors,Publishers,Titles,Title_Authors,Royalties; DROP TABLES IF EXISTS Products,Customers,Orders,Order_details; DROP TABLES...
describe what these mysql queries do 1.) select lastname, firstname, region, birthday from Members where birthday...
describe what these mysql queries do 1.) select lastname, firstname, region, birthday from Members where birthday in (select birthday from Members where email is not null) 2.) select Sales.Firstname As EmpFirst, Sales.Lastname as EmpLast, Sup.Firstname as SupFirst, Sup.Lastname as SupLast from Salespeople Sales inner join Salespeople Sup On Sales.Supervisor=Sup.SalesID 3.) select Region, Gender, Count(*) As Num from Members where Email is null group by region, gender 4.) select title from titles where not Genre = 'Jazz';
Explain the following code. What language? What does it do? What is the result? SELECT date_trunc('month',date),avg(value)...
Explain the following code. What language? What does it do? What is the result? SELECT date_trunc('month',date),avg(value) FROM rain GROUP BY date_trunc ('month',date) ORDER BY date_trunc('month',date);
Explain the following code. What language? What does it do? What is the result? SELECT date_trunc('month',date),avg(value)...
Explain the following code. What language? What does it do? What is the result? SELECT date_trunc('month',date),avg(value) FROM rain GROUP BY date_trunc ('month',date) ORDER BY date_trunc('month',date);
Introdyction to database Topic SQL Q2) what is the purpose of following statements? SELECT DISTINCT SELECT...
Introdyction to database Topic SQL Q2) what is the purpose of following statements? SELECT DISTINCT SELECT DESC AND ORDER BY AS
Which statement is true of an e-distributor? a. An e-distributor offers services from different vendors in...
Which statement is true of an e-distributor? a. An e-distributor offers services from different vendors in separate packages. b. An e-distributor provides products and services at high prices. c. An e-distributor offers fast delivery of a wide selection of products and services. d. An e-distributor is responsible for distributing a handheld catalog of products.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT