Question

In: Computer Science

1. Write a query to: a. select data from INVOICES table as follows: Invoice date in...

1. Write a query to:

a. select data from INVOICES table as follows:

  • Invoice date in MM/DD/YYYY format
  • Invoice Date in DD-Mon-YYYY format
  • Invoice Total rounded to the nearest dollar

Note: you can alias columns as you sit fit

b. select data from VENDORS table as follows:

  • Vendor Name
  • Concatenate Vendor Name with the string ‘s Address
  • Concatenate Vendor City, Vendor State and Vendor Zip Code (alias this)

Your output should look like this (this is just an example of it). Note how after each vendor name there is ‘s

vendor_name Vendor Address
Register of Copyrights Register of Copyright's Address: Washington, DC 20076
Newbrige Book Clubs Newbrige Book's Address: Los Angeles, CA 90045

Solutions

Expert Solution

1.a)

Select str_to_date(invoicedate, "%m/%d/%Y") AS "Invoices Date in MM/DD/YYYY format" , str_to_date(invoiceDate, "%d.%m.%Y") AS "Invoices Date in DD-MM-YYYY format" , ROUND( InvoiceTotal, 2) AS "Rounded Invoice Total" from INVOICES;

Here we use date function to convert the format of date from standard format to the given format:

string to date(str_to_date) function is used in order to convert invoice date into month, date, and then year (MM/DD/YYYY) format.

Similarly to convert the date into date month and year(DD-MM-YYYY) format, we use the same string to date (str_to_date) function.

Although there is another function that can be used but (str_to_date) function is quite easy.

If you want any specific date column in any other particular format, then you have to use DATE_FORMAT() function in which you have to mention it's original format in another condition.

For example:

DATE_FORMAT( STR_TO_DATE( nameofdatecolumn , "%d/%m/%Y" ) , "%Y/%m/%d" )

For rounding to the nearest dollar, we use ROUND function which can Round up the invoice total upto 2 decimal positions from INVOICES TABLE and we alias all these fields in their respective names written in the command.

1.b)

Select vendor_name, CONCAT(Vendor_name, " 's Address: ") AS Vendor, CONCAT(vendorCity, vendorState, vendorzipcode) AS Address from VENDORS;

In this query, we use CONCAT (concatenation) function in order to concatenate vendors name with " 's Address " and for concatenating vendor City, vendor state, vendor zip code, we use CONCAT function to concat all the field records and alias them in the respective name written in the expected output the question.


Related Solutions

1. Select all Course table data and display in primary key order. Show this query result.
Table Course:    Column    dataType Constraint ccode char(8) primary key, meetingTime char(4), room char(6), fid    decimal(3) NOT NULL, cTitle    varchar(24) NOT NULL, fee    decimal(4,2),    prereq char(8) 1. Select all Course table data and display in primary key order. Show this query result. 2. By default MySQL runs in autocommit mode. Issue a START TRANSACTION command before a series of update commands that may need to be rolled back or to be committed. ROLLBACK will "undo" commands given in the transaction. [Note:...
Write a query to return the date and day of the week of the first day...
Write a query to return the date and day of the week of the first day of the month two years from today. If today is 10/16/20, then the expect output is 10/01/2022 and the day of the week is thursday. I am using postgresql.
Choose all the optional query block in “Select “retrieval query? A. Select B. Where C. From...
Choose all the optional query block in “Select “retrieval query? A. Select B. Where C. From D. Order By A NULL value means A. Value missing B. Value unknown C. More than 1000 D. All the above Delete from DEF; /*DEF is a table/relation*/ What action does this command perform? A. Delete the table B. Delete all the rows from the table C. Deletes a column D. Deletes the top 10 tuples A attribute/column, fName, is of Data Type varchar(100)....
Question 1. Write the statement to increase the invoice_total by 25% using the INVOICES table for...
Question 1. Write the statement to increase the invoice_total by 25% using the INVOICES table for all vendors whose vendor_id is less than 100. Question 2. Write the statement to answer the following question: What is the total of the invoice_total amounts after the update. I need your statement and the result stated here. Question 3. Write the statements to list the customer ID and Order ID from the ORDERS table for all orders with order id greater than 700....
Problem 1. Using the INVOICE table structure shown in table below do the following: INVOICE Attribute...
Problem 1. Using the INVOICE table structure shown in table below do the following: INVOICE Attribute Name Sample Value Sample Value Sample Value Sample Value Sample Value INV_NUM 211347 211347 211347 211348 211349 PROD_NUM AA-E3422QW QD-300932X RU-995748G AA-E3422QW GH-778345P SALE_DATE 15-Jan-2016 15-Jan-2016 15-Jan-2016 15-Jan-2016 16-Jan-2016 PROD_LABEL Rotary sander 0.25-in. drill bit Band saw Rotary sander Power drill VEND_CODE 211 211 309 211 157 VEND_NAME NeverFail, Inc. NeverFail, Inc. BeGood, Inc. NeverFail, Inc. ToughGo, Inc. QUANT_SOLD 1 8 1 2 1...
Please write the correct query for the following questions: Select the name of each manufacturer along...
Please write the correct query for the following questions: Select the name of each manufacturer along with the name and price of its most expensive product. Computer products are expensive. Find the maximum priced product. Which products are within $30 of the maximum priced product. Find the maker of the most expensive ‘drive’. Note, there are variety of drives in the data. Regular expressions help. Using the following table: CREATE TABLE manufacturers ( code number PRIMARY KEY NOT NULL, name...
The experiment data in below table was to evaluate the effects of three variables on invoice...
The experiment data in below table was to evaluate the effects of three variables on invoice errors for a company. Invoice errors had been a major contributor to lengthening the time that customers took to pay their invoices and increasing the accounts receivables for a major chemical company. It was conjectured that the errors might be due to the size of the customer (larger customers have more complex orders), the customer location (foreign orders are more complicated), and the type...
From the following mySql query create a function that returns a nth value of a table:...
From the following mySql query create a function that returns a nth value of a table: SELECT name, (SUM(price * quantity)) AS TotalPrice FROM Items NATURAL JOIN Inventory GROUP BY name ORDER BY (TotalPrice) DESC LIMIT 1, OFFSET 1; Shema: Inventory(name: String,item:String,quantity:integer) Items(item: String, brand: String, price:double)
Create a ‘Student’ table using SQL query. The table must have at least five attributes from...
Create a ‘Student’ table using SQL query. The table must have at least five attributes from your choice with different data types.
The ProjectsAndLineItems query currently uses the ProjectID field from the Projects table. Explain why that field cannot be edited in Query Datasheet View.
The ProjectsAndLineItems query currently uses the ProjectID field from the Projects table. Explain why that field cannot be edited in Query Datasheet View. 
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT