168k views
1 vote
write a query to display the customer name and password. password should be generated by concatenating the first three characters of customer name, length of the customer name and the last three numbers in phone number and give an alias name as customer password. sort the result based on customer name in descending order. (hint: use customer info to retrieve records)

1 Answer

0 votes

Below is the SQL query that retrieves the customer name and generates a password according to the specified criteria, aliasing it as 'customer_password'.

The result set is sorted in descending order based on the customer name.

SELECT

customer_name,

CON CAT ( LEFT(customer_name, 3), LENGTH(customer_name), RIGHT(phone_number, 3)) AS customer_password

FROM

customer_info

ORDER BY

customer_name DESC;

This query utilizes the CONCAT function to combine the first three characters of the customer name, the length of the customer name, and the last three numbers in the phone number to generate the 'customer_password' alias.

The ORDER BY clause sorts the result set based on the customer name in descending order.

User Gentian
by
7.3k points