Write a query to display the first 3 characters of each meter number. Give an alias name for the meter number as 'meter_code'.Display the records sorted by meter_code in descending order.
Question
Write a query to display the first 3 characters of each meter number. Give an alias name for the meter number as 'meter_code'.Display the records sorted by meter_code in descending order.
Solution
Here is the SQL query you need:
SELECT SUBSTRING(meter_number, 1, 3) AS meter_code
FROM your_table_name
ORDER BY meter_code DESC;
Please replace your_table_name with the actual name of your table. This query will select the first three characters of each meter_number and alias it as meter_code. The ORDER BY clause is used to sort the results in descending order by meter_code.
Similar Questions
Write a query to display the meter_number and updated_meter_number(which is obtained by left padding meter_number with ‘*’ and making it 10 character length field.) . Give an alias name as 'updated_meter_number'. Display the records in ascending order based on meter_number.Note:1. Display only the meter_number and updated_meter_number from meter table. updated_meter_number is obtained by left padding meter_number with ‘*’ and making it 10 character length field.2. Specify the alias name without any mistake.3. Order by is mandatory4. Compare your executed result with the sample output given below.Sample output:[only few records shown here]
Write a query to display all 'meter_number' from meter table.
Write a query to display the meter_number from the meter table which got minimum amount of total_units in a month. Display the records in ascending order based on their meter_number.Note:1. Display only the meter_number from the meter table which got minimum amount of total_units in a month.2. Tables involved are meter and bill3. Order by is mandatory4. Compare your executed result with the sample output given below.Sample output:
Write a query to display all the details of the 'meter' whose meter_number starts with 'S' and ends with '6'.
Write a query to display all the details of the 'meter' whose meter_number starts with 'S' and ends with '6'.Note:1. Display all the columns present in the meter table.2. Specify the condition and retrieve the correct rows in the result. (condition need to be specified on meter_number column)3. You can compare your executed result with the sample output given below.Sample output:
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.