Question
Write an SQL query to get the list of customers' full names with their countries and phone numbers. The customer full name is a space-delimited
Write an SQL query to get the list of customers' full names with their countries and phone numbers.
The customer full name is a space-delimited concatenation of the title (if it exists), first_name, and last_name fields. If the suffix field is present, it should be appended enclosed in parenthesis. In other words, output the full name in the following format:
Output phone numbers in the following format:
Be sure to include all customers, even if they are missing some information.
Sort the results alphabetically by country and then by phone number in ascending order within each country.
I currently have this:
select CONCAT(c.title,' ' ,c.first_name, ' ',c.last_name,' ',c.suffix) AS "full name", pa.country, concat(p.phone_country_code, '-', p.phone_area_code, '-', p.phone_number) as "phone number"
from customer as c -- from customer table with an alias name c left join customer_address AS ca on c.customer_id = ca.customer_id left join physical_address AS pa on ca.physical_address_id = pa.physical_address_id left join phone_number as p on c.customer_id = p.customer_id
order by pa.country, p.phone_number asc
but I am unsure of how to put the parenthesis arround suffix if exists and the order seems to be off
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started