Write a query to display the meter number,owner name,address,contact number,building type name and connection name of all buildings.Display the records in ascending order based on building type name.Note:1. Display only the below 6 columns, i. meter number ii. owner name iii. address iv. contact number v. building type name vi. Connection name 2. Use Joins3. Tables involved building, meter, building_type, electricity_connection_type4. Order by is mandatory.5. Compare your executed result with the sample output given below.
Question
Write a query to display the meter number,owner name,address,contact number,building type name and connection name of all buildings.Display the records in ascending order based on building type name.Note:1. Display only the below 6 columns, i. meter number ii. owner name iii. address iv. contact number v. building type name vi. Connection name 2. Use Joins3. Tables involved building, meter, building_type, electricity_connection_type4. Order by is mandatory.5. Compare your executed result with the sample output given below.
Solution
The SQL query for the given problem would look something like this:
SELECT
m.meter_number,
b.owner_name,
b.address,
b.contact_number,
bt.building_type_name,
ect.connection_name
FROM
building b
JOIN
meter m ON b.building_id = m.building_id
JOIN
building_type bt ON b.building_type_id = bt.building_type_id
JOIN
electricity_connection_type ect ON b.connection_type_id = ect.connection_type_id
ORDER BY
bt.building_type_name ASC;
Here's what this query does:
- It selects the required columns from the
building,meter,building_type, andelectricity_connection_typetables. - It uses
JOINclauses to combine these tables based on their relationships. Thebuildingtable is joined with themetertable onbuilding_id, with thebuilding_typetable onbuilding_type_id, and with theelectricity_connection_typetable onconnection_type_id. - Finally, it orders the results in ascending order based on the
building_type_namecolumn.
Similar Questions
Write a query to display the building owner name ,address and number of connections present in each building. Display the records in ascending order based on owner name.Give an alias name as connection_count.Note:1. Display only the building owner_name ,address and number of connections.2. Use Joins3. Tables involved building, building_type, meter4. Specify the alias name without any mistake.5. Order by is mandatory. 6. Compare your executed result with the sample output given below.
QueryQ2Write a query to display the meter number,owner name,address and contact number of all the buldings. Display the record in ascending order based on owner name.Note:1. Display only the below 4 columns, i. meter number ii. owner name iii. address iv. contact number 2. Use Joins3. Tables involved building and meter4. Order by is mandatory.5. Compare your executed result with the sample output given below.Sample output: [Only few records are shown here]
Write a query to display the meter_number of the building_type named 'College'. Display the records in ascending order based on their meter_number.Note:1. Display only the meter_number column present in the meter table where building_type name is ‘College’. Use subqueries to achieve this.2. Tables involved are building_type, building and meter.3. Order by is mandatory4. Compare your executed result with the sample output given below.
Write a query to display the owner_name and contact_number of all building, Display the records in ascending order based on owner_name.Note:1. Display only the column named ‘owner_name’ and ‘contact_number’ present in the building table.2. Order by is mandatory
Write a query to display the meter_number,owner_name and address of the owner who paid fine most number of times. If there are multiple records display in ascending order based on owner_name.Note:1. Display only the below 3 columns, i. meter_number ii. owner_name iii. address with the condition who paid fine most number of times.2. Use Joins3. Tables involved are building, meter and bill4. Order by is mandatory.5. Compare your executed result with the sample output given below.
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.