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.
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.
Solution
Here is the SQL query you need:
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 ...selects thetotal_unitsandpayable_amountfrom thebilltable where themeter_numbermatches the one selected in the subquery.
Similar Questions
Write a query to display the total_units and payable_amount of the particular meter number 'SG934826
Write a query to display all 'meter_number' from meter table.
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:
Create a view named "all_payable_amount" to select the meter_number from meter table and its corresponding payable_amount from the bill table.Note:1. Do not change the name of the view2. Include only 2 columns, meter_number from meter table and its corresponding payable_amount from the bill table.3. Use Joins. Tables involved are meter and bill4. Submit only the CREATE VIEW query.Instructions:1. Create the view successfully2. Once the view is created, check the correctness of the virtual table by displaying all the records in it.3. DO NOT submit the select query. Submit only the CREATE VIEW query.Sample Output:Created view will contain the following same data:
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:
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.