Knowee
Questions
Features
Study Tools

Write a query to display the month and sum of fine_amount collected on the month between July to October. Give an alias name as 'monthly_fine_amount' also display the records in ascending order based on month.Note:1. Display only the month and sum of fine_amount collected in the month between July to October from bill table. (month will be 01, 02, 03,...12)2. Specify the alias name without any mistake.3. Order by is mandatory4. Group by month to get the month wise sum of fine_amount5. Compare your executed result with the sample output given below.

Question

Write a query to display the month and sum of fine_amount collected on the month between July to October. Give an alias name as 'monthly_fine_amount' also display the records in ascending order based on month.Note:1. Display only the month and sum of fine_amount collected in the month between July to October from bill table. (month will be 01, 02, 03,...12)2. Specify the alias name without any mistake.3. Order by is mandatory4. Group by month to get the month wise sum of fine_amount5. 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 query you're asking for would look something like this:

SELECT 
    MONTH(bill_date) AS month, 
    SUM(fine_amount) AS monthly_fine_amount
FROM 
    bill
WHERE 
    MONTH(bill_date) BETWEEN 7 AND 10
GROUP BY 
    MONTH(bill_date)
ORDER BY 
    MONTH(bill_date);

Here's a step-by-step breakdown of this query:

  1. SELECT MONTH(bill_date) AS month, SUM(fine_amount) AS monthly_fine_amount: This line is selecting the month from the bill_date column and the sum of the fine_amount column. The AS keyword is used to give these selected columns new names (or aliases), month and monthly_fine_amount.

  2. FROM bill: This line is specifying the bill table as the source of the data.

  3. WHERE MONTH(bill_date) BETWEEN 7 AND 10: This line is filtering the data to only include records where the month of the bill_date is between July (7) and October (10).

  4. GROUP BY MONTH(bill_date): This line is grouping the selected data by the month of the bill_date, which allows the SUM(fine_amount) to calculate the total fine amount for each month.

  5. ORDER BY MONTH(bill_date): This line is ordering the results by the month of the bill_date in ascending order (from July to October).

This problem has been solved

Solution 2

The query you're asking for would look something like this:

SELECT 
    MONTH(bill_date) AS month, 
    SUM(fine_amount) AS monthly_fine_amount
FROM 
    bill
WHERE 
    MONTH(bill_date) BETWEEN 7 AND 10
GROUP BY 
    MONTH(bill_date)
ORDER BY 
    MONTH(bill_date);

Here's a step-by-step breakdown of this query:

  1. SELECT MONTH(bill_date) AS month, SUM(fine_amount) AS monthly_fine_amount: This line is selecting the month from the bill_date column and the sum of the fine_amount column. The AS keyword is used to give these selected columns new names (or aliases) for this query.

  2. FROM bill: This line is specifying the table that we're selecting data from, which is the bill table.

  3. WHERE MONTH(bill_date) BETWEEN 7 AND 10: This line is filtering the data so that only rows where the month of the bill_date is between July (7) and October (10) are included.

  4. GROUP BY MONTH(bill_date): This line is grouping the selected data by the month of the bill_date, which allows us to calculate the sum of the fine_amount for each month.

  5. ORDER BY MONTH(bill_date): This line is ordering the results by the month of the bill_date in ascending order.

Please replace bill_date and fine_amount with your actual column names if they are different.

This problem has been solved

Similar Questions

Write a query to display the month and sum of fine_amount collected on the month between July to October. Give an alias name as 'monthly_fine_amount' also display the records in ascending order based on month.

Write a query to display the entire contents of bill table. Display the records sorted in ascending order based on month and then in descending order based on total_units.

Write a query to display the count of bills which has completed payment without fine on the month of October 2017. Give an alias name as 'bills_paid_withoutfine'.Note:1. Display only the count of bills which has completed payment without fine on the month of October 2017 from bill table.2. Specify the alias name without any mistake.3. Specify condition on payment_date and fine_amount. payment_date must be NOT NULL and it must be October 2017 and fine_amount must be NULL.4. Compare your executed result with the sample output given below.Sample output:

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.

Write a query to display the average fine_amount of the bills whose payment_date is on the year 2018. Give an alias name to the average fine amount as 'average_fine_amount'.Note:1. Display only the average fine_amount with the given payment_date 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 fine amount).4. Compare your executed result with the sample output given below.Sample output:

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.