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:
Question
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:
Solution
Here is the SQL query you need to write to get the desired output:
SELECT total_units, payable_amount
FROM bill
WHERE meter_number IN (SELECT meter_number FROM meter WHERE meter_number = 'SG934826');
This query works as follows:
-
The subquery
(SELECT meter_number FROM meter WHERE meter_number = 'SG934826')selects the meter number 'SG934826' from themetertable. -
The main query
SELECT total_units, payable_amount FROM bill WHERE meter_number IN ...then selects thetotal_unitsandpayable_amountfrom thebilltable where themeter_numbermatches the one selected in the subquery.
Please replace the table and column names if they are different in your database.
Similar Questions
Write a query to display the total_units and payable_amount of the particular meter number 'SG934826
Write a query to display the meter_number from the meter table for which the bill is paid with maximum fine_amount of a month.Note:1. Display only the meter_number from the meter table for which the bill is paid with maximum fine_amount of a month.2. Tables involved are meter and bill3. 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 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 all 'meter_number' from meter table.
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.