Write a query to display the average of payable_amount from the bill table for the buildings with electricity connection slab rate less than 24. Give an alias name for payable amount as 'payable_amount'.Note:1. Display only the average of payable_amount from the bill table for the buildings with electricity connection slab rate less than 24.2. Tables involves are bill, meter, building, building_type, electricity_connection_type and slab.3. Specify the alias name without any mistake.4. Compare your executed result with the sample output given below.
Question
Write a query to display the average of payable_amount from the bill table for the buildings with electricity connection slab rate less than 24. Give an alias name for payable amount as 'payable_amount'.Note:1. Display only the average of payable_amount from the bill table for the buildings with electricity connection slab rate less than 24.2. Tables involves are bill, meter, building, building_type, electricity_connection_type and slab.3. Specify the alias name without any mistake.4. Compare your executed result with the sample output given below.
Solution
Here is the SQL query that you need:
SELECT AVG(b.payable_amount) AS payable_amount
FROM bill b
JOIN meter m ON b.meter_id = m.id
JOIN building bu ON m.building_id = bu.id
JOIN building_type bt ON bu.building_type_id = bt.id
JOIN electricity_connection_type ect ON bt.electricity_connection_type_id = ect.id
JOIN slab s ON ect.slab_id = s.id
WHERE s.rate < 24;
This query works as follows:
- It joins the
billtable with themetertable on themeter_idfield. - Then it joins the result with the
buildingtable on thebuilding_idfield. - The result is then joined with the
building_typetable on thebuilding_type_idfield. - The
electricity_connection_typetable is joined on theelectricity_connection_type_idfield. - Finally, the
slabtable is joined on theslab_idfield. - The
WHEREclause filters out the records where theratein theslabtable is less than 24. - The
SELECTstatement calculates the average of thepayable_amountfrom thebilltable and gives it an alias name 'payable_amount'.
Similar Questions
Write a query to display the sum of h20 and average of h20 from the electricity_reading table consumed by the building_type named as 'Commercial' on 8PM. Give an alias name for total as 'total_amount' and average as 'average_amount'.Note:1. Display only the sum of h20 and average of h20 from the electricity_reading table consumed by the building_type named as 'Commercial' on 8PM.2. Tables involved are electricity_reading, meter, building, building_type and electricity_connection_type3. Specify the alias name without any mistake.4. Compare your executed result with the sample output given below.
Write a query to display the average payable_amount from bill table where payable_amount is greater than 10000. Give an alias name to the average payable amount as 'average_payable_amount'.Note:1. Display only the average payable_amount with the given payable_amount from bill table.2. Specify the alias name without any mistake.3. Specify the condition and retrieve the correct rows in the result(condition need to be specified on payable_amount).3. Compare your executed result with the sample output given below.Sample outp
Write a query to display the average total_units of electricity consumption from the electricity_reading table.Give an alias name to the average units as 'average_units_of_electricity'.Note:1. Display only the average total_units of electricity consumption from electricity reading.2. Specify the alias name without any mistake.3. Compare your executed result with the sample output given below.Sample output:
Write a query to display the average 8th hour unit consumption from electricity reading. Give an alias name to the average 8th hour consumption as 'average_8th_hour_consumption'.Note:1. Display only the average 8th hour unit consumption from electricity reading.(8th hour reading will be h8 column).2. Specify the alias name without any mistake.3. Compare your executed result with the sample output given below.Sample output:
Write a query to display the number of bills from the bill table which are payed for the building with connection_type 'Commercial'. Give an alias name as 'payment_count'.Note:1. Display only the number of bills from the bill table which are payed(is_payed=1) for the building with connection_type 'Commercial'.2. Tables involves are bill, meter, building, building_type and electricity_connection_type.3. Specify the alias name without any mistake.4. 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.