Question: Write a SELECT statement that returns these columns from the Products and Orders table: The product_name column The card_number column The length of the card_number

Write a SELECT statement that returns these columns from the Products and Orders table: The product_name column The card_number column The length of the card_number column The last four digits of the card_number column When you get that working right, add the following columns to the result set. This is more difficult because these columns require the use of functions within functions. A column that displays the last four digits of the card_number column in this format: XXXX-XXXX-XXXX-1234. In other words, use Xs for the first 12 digits of the card number and actual numbers for the last four digits of the number. A column that returns the third word in the product_name in the products table. If there is no third word, it should return an empty string. You can do this using IF and SUBSTRING_INDEX. Hint, this is complicated, the idea is that you write expression2 using SUBSTRING_INDEX that will return the 1st word if there is only one word, or the 2nd word if there are 2 words. Write expression3 using SUBSTRING_INDEX that will return the 1st word if there is only one word, or the 2nd word if there are 2 words and the 3rd word if there are three words. Then combine expression2 and expression3 with if as follows: IF ( expression2 != expresion3 , expression3, '') AS third_name Order by product_name

USE my_drum_shop;

based on Murach MySql book

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!