Knowee
Questions
Features
Study Tools

Write a query to display the owner_name, building_type name,  meter_number and payment_status of the bill which are raised in the month December 2017.Payment_Status will be payment_date is the payment is done, else if the payment is not done then display as 'Not Paid Yet'. Give an alias name as 'Payment_Status'. Display the record in ascending order based on owner_name.Note:1. 1. Display only the below 4 columns,     i. owner_name     ii. building_type name     iii. meter_number     iv. payment_statusraised in the month december 2017.2. Use Joins3. Tables involved are bill, meter, building and building_type4. Specify condition on year, month of bill table.5. Order by is mandatory. 6. Specify the alias name without any mistake.7. Compare your executed result with the sample output given below.

Question

Write a query to display the owner_name, building_type name,  meter_number and payment_status of the bill which are raised in the month December 2017.Payment_Status will be payment_date is the payment is done, else if the payment is not done then display as 'Not Paid Yet'. Give an alias name as 'Payment_Status'. Display the record in ascending order based on owner_name.Note:1. 1. Display only the below 4 columns,     i. owner_name     ii. building_type name     iii. meter_number     iv. payment_statusraised in the month december 2017.2. Use Joins3. Tables involved are bill, meter, building and building_type4. Specify condition on year, month of bill table.5. Order by is mandatory. 6. Specify the alias name without any mistake.7. Compare your executed result with the sample output given below.

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

Solution 1

The question is asking for a SQL query. Here is a step-by-step guide on how to write it:

  1. Identify the tables involved: bill, meter, building, and building_type.
  2. Identify the columns to be displayed: owner_name, building_type name, meter_number, and payment_status.
  3. Understand the conditions: The bill should be raised in December 2017, and the payment_status should display 'payment_date' if the payment is done, else 'Not Paid Yet'.
  4. Understand the order: The records should be displayed in ascending order based on owner_name.

Here is the SQL query based on the above information:

SELECT 
    b.owner_name, 
    bt.name AS building_type_name, 
    m.meter_number, 
    CASE 
        WHEN bill.payment_date IS NULL THEN 'Not Paid Yet' 
        ELSE bill.payment_date 
    END AS Payment_Status
FROM 
    bill 
JOIN 
    meter m ON bill.meter_id = m.id 
JOIN 
    building b ON m.building_id = b.id 
JOIN 
    building_type bt ON b.building_type_id = bt.id 
WHERE 
    YEAR(bill.date) = 2017 AND MONTH(bill.date) = 12 
ORDER BY 
    b.owner_name ASC;

This query first joins the necessary tables based on their relationships. It then selects the required columns, using a CASE statement to determine the Payment_Status. It filters the results to only include bills from December 2017, and finally orders the results by owner_name in ascending order.

This problem has been solved

Solution 2

The question is asking for a SQL query. Here is a step-by-step guide on how to write it:

  1. Identify the tables involved: bill, meter, building, and building_type.
  2. Identify the columns to be displayed: owner_name, building_type name, meter_number, and payment_status.
  3. Understand the conditions: The bill should be raised in December 2017, and the payment_status should display 'payment_date' if the payment is done, else 'Not Paid Yet'.
  4. Understand the order: The records should be displayed in ascending order based on owner_name.

Here is the SQL query based on the above information:

SELECT 
    b.owner_name, 
    bt.name AS building_type_name, 
    m.meter_number, 
    CASE 
        WHEN bill.payment_date IS NULL THEN 'Not Paid Yet' 
        ELSE bill.payment_date 
    END AS Payment_Status
FROM 
    bill 
JOIN 
    meter m ON bill.meter_id = m.id 
JOIN 
    building b ON m.building_id = b.id 
JOIN 
    building_type bt ON b.building_type_id = bt.id 
WHERE 
    YEAR(bill.date) = 2017 AND MONTH(bill.date) = 12 
ORDER BY 
    b.owner_name ASC;

This query first joins the necessary tables based on their relationships. It then selects the required columns, using a CASE statement to determine the Payment_Status. It filters the results to only include bills from December 2017, and finally orders the results by owner_name in ascending order.

This problem has been solved

Similar Questions

Write a query to display owner name,address ,meter number and payable amount of all the bill which are all not having fine_amount and that are generated for 2017 December. Display the records in ascending order based on owner name.Note:1. Display only the below 4 columns,     i. owner name     ii. address     iii. meter number     iv. payable_amountwith the condition not having fine_amount that are generated for 2017 December.2. Use Joins3. Tables involved building, meter and bill4. Specify condition on year, month and fine_amount columns of bill table. year must be 2017, month must be 12 and fine_amount should be not null5. Order by is mandatory. 6. Compare your executed result with the sample output given below.

Write a query to display all the 'bills' with 'meter' details. Display the records in ascending order based on meter number.Note:1. Display all the columns of bill and meter table2. Use Joins3. Tables involved bill and meter4. Order by is mandatory5. Compare your executed result with the sample output given below.Sample output: [Only few records are shown here]ID METER_ID MONTH YEAR DUE_DATE TOTAL_UNITS PAYABLE_AMOUNT IS_PAYED PAYMENT_D FINE_AMOUNT ID METER_NUMBER BUILDING_ID39 26 8 2017 01-SEP-17 20700 724500 1 14-SEP-17 72450 26 SG190123 2614 10 10 2017 01-NOV-17 750 16875 1 09-NOV-17 1687.5 10 SG198329 10

Write a query to display bill id, meter_id, month, year, total_units, payable_amount and due_date of all the bills. Display the due_date in the format like June 17, 2003. Give an alias name as 'formatted_due_date'. Display all the records sorted in ascending order based on bill id.

Write a query to display the details of all the 'bill' with the due_date on '2017-10-01'.Display the records in descending order based on their payable_amount.

Write a query to display the owner_name and sum of payable_amount who paid the maximum bill amount in the year 2017. If there are multiple records display the record in ascending order based on owner_name Give an alias name as "TotalBillAmount".Note:1. Display only the owner_name and sum of payable_amount who paid the maximum bill amount in the year 2017.2. Use Joins3. Tables involved building, meter and bill4. Specify condition on year column of bill table. sum of payable_amount must be maximum in this year.5. Order by is mandatory. 6. 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.