Knowee
Questions
Features
Study Tools

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.

...expand
🧐 Not the exact question you are looking for?Go ask a question

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:

  1. It joins the bill table with the meter table on the meter_id field.
  2. Then it joins the result with the building table on the building_id field.
  3. The result is then joined with the building_type table on the building_type_id field.
  4. The electricity_connection_type table is joined on the electricity_connection_type_id field.
  5. Finally, the slab table is joined on the slab_id field.
  6. The WHERE clause filters out the records where the rate in the slab table is less than 24.
  7. The SELECT statement calculates the average of the payable_amount from the bill table and gives it an alias name 'payable_amount'.

This problem has been solved

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.

1/3

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.