Header Ads Widget

Country code | hackerrank Mysql certification solution

Country code | hackerrank Mysql certification solution 

A company wants to contact each of its customers regarding the policy changes. They have international customers, but their database does not include country codes with their phone numbers.

There are two tables in the database: customers and country codes. The first table contains details of every customer including customer_id, name, phone number, and country. The second table contains the country code for every country.

Write a query to retrieve a list of all customer ids, names, and phone numbers, with their country codes concatenated with their phone numbers. Sort the output in the order of their customer_id

Note: The phone number should be in the following format +COUNTRY CODE PHONENUMBER (without spaces)

                 

Country code | hackerrank Mysql certification solution 

Write a query to retrieve a list of all customer ids, names, and phone numbers, with their country codes concatenated with their phone numbers. Sort the output in the order of their customer_id .

Schema :-




Sample:-


Output:-

1 Raghav +91951341341
2 Jake +152341351
3 Alice +1613413


Explanation:

Since Raghav is from India, the country code is 91, so the complete phone number is +91951341341
Since Jake is from the USA, the country code is 1, and the complete phone number is +152341351
Since Alice is from the USA, the country code is 1, and the complete phone number is +161341351

Mysql code :-

select c.customer_id ,c.name , concat("+",cc.country_code,c.phone_number) from
customer c left join country_codes cc on c.country=cc.country order by c.customer_id






Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments