Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions