Knowee
Questions
Features
Study Tools

Write a query to display the number of  the buildings who has given the fine amount.Give an alias name as 'building_count'.Note:1. Display only the number of buildings from the building table who has given the fine_amount. Use subqueries to achieve this.2. Tables involved are building, meter and bill.3. Specify the alias name without any mistake.4. Compare your executed result with the sample output given below.Note:1. Display only the number of  the buildings who has given the fine amount from bill table.2. Specify the alias name without any mistake.3. Compare your executed result with the sample output given below.

Question

Write a query to display the number of  the buildings who has given the fine amount.Give an alias name as 'building_count'.Note:1. Display only the number of buildings from the building table who has given the fine_amount. Use subqueries to achieve this.2. Tables involved are building, meter and bill.3. Specify the alias name without any mistake.4. Compare your executed result with the sample output given below.Note:1. Display only the number of  the buildings who has given the fine amount from bill table.2. Specify the alias name without any mistake.3. Compare your executed result with the sample output given below.

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

Solution

Based on the information provided, it seems you are looking for a SQL query. Here is a step-by-step guide on how to write this query:

  1. Identify the tables involved: In this case, we have three tables - building, meter, and bill.

  2. Understand the relationship between these tables: Usually, a building has one or more meters, and each meter has one or more bills associated with it.

  3. Identify the field that indicates if a fine has been given: This is likely to be in the bill table, let's assume it's called 'fine_amount'.

  4. Write the query: We want to count the number of buildings that have at least one bill with a fine. This can be achieved using subqueries. Here is a possible query:

SELECT COUNT(DISTINCT b.building_id) AS building_count
FROM building b
WHERE EXISTS (
    SELECT 1
    FROM meter m
    JOIN bill bi ON m.meter_id = bi.meter_id
    WHERE b.building_id = m.building_id AND bi.fine_amount > 0
);

This query works as follows:

  • The outer query goes through each building.
  • The subquery checks if there is at least one bill with a fine for a meter in the current building.
  • If such a bill exists, the building is included in the count.

Please replace 'building_id', 'meter_id', and 'fine_amount' with the actual column names in your tables if they are different.

This problem has been solved

Similar Questions

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.

Write a query to display the number of bills having fine_amount. Give an alias name as 'count_of_bills_with_fine'.Note:1. Display only the number of bills having the fine_amount from bill table. (If fine_amount is greater than 0 then it indicates that bill got fine_amount.)2. Specify the alias name without any mistake.3. Specify condition on fine_amount column of bill table.3. Compare your executed result with the sample output given below.Sample output:

Write a query to display the sum of payable_amount and fine_amount of all the bills from bill table. Give an alias name to the sum of payable amount and fine amount as 'sum_payable_and_fine_amount'.Note:1. Display only the sum of payable_amount and fine_amount from bill table.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 total_units and payable_amount of the particular meter number 'SG934826'.Note:1. Display only the total_units and payable_amount columns present in the bill table where meter_number is ‘SG934826’. Use subqueries to achieve this.2. Tables involved are bill and meter.3. Compare your executed result with the sample output given below.Sample output:

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.

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.