This is for my SQL class: Complete the Task 2 in answering the following questio
ID: 3723327 • Letter: T
Question
This is for my SQL class:
Complete the Task 2 in answering the following questions using Publishers database (Hint: The following questions contain concepts from Chapter 4 and Chapter 8).
1. SELECT a character string composed of the last two digits of the year of a title's pubdate, the pub_id, and the first ten characters of the title.
2. Display in one query output table the “id”, “name”, city, and state of both publishers and stores.
3. Write a SELECT statement that returns these columns from the Titles table:
The price column
A column that uses the CAST function to return the price column with 1 digit to the right of the decimal point
A column that uses the CONVERT function to return the price column as an integer
A column that uses the CAST function to return the price column as an integer
I attempted the first question but kept getting "Incorrect syntax near 'SUBSTRING'. Here's my code:
SELECT SUBSTRING(YEAR_OF_PUBDATE,LEN(YEAR_OF_PUBDATE)-2,LEN(YEAR_OF_PUBDATE))
PUB_ID SUBSTRING(TITLE,1,10)
FROM PUBLISHER;
Explanation / Answer
1. SELECT CONCAT(RIGHT(YEAR_OF_PUBDATE,2),PUB_ID,SUBSTRING(TITLE,1,10)) FROM PUBLISHER;
2. SELECT id,name,city,state FROM publishers UNION SELECT id,name,city,state FROM stores;
3.SELECT CAST(price AS decimal(10,1)),CONVERT(int,price), CAST(price AS int) FROM Titles
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.