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.
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:
-
SELECT MONTH(bill_date) AS month, SUM(fine_amount) AS monthly_fine_amount: This line is selecting the month from thebill_datecolumn and the sum of thefine_amountcolumn. TheASkeyword is used to give these selected columns new names (or aliases),monthandmonthly_fine_amount. -
FROM bill: This line is specifying thebilltable as the source of the data. -
WHERE MONTH(bill_date) BETWEEN 7 AND 10: This line is filtering the data to only include records where the month of thebill_dateis between July (7) and October (10). -
GROUP BY MONTH(bill_date): This line is grouping the selected data by the month of thebill_date, which allows theSUM(fine_amount)to calculate the total fine amount for each month. -
ORDER BY MONTH(bill_date): This line is ordering the results by the month of thebill_datein ascending order (from July to October).
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:
-
SELECT MONTH(bill_date) AS month, SUM(fine_amount) AS monthly_fine_amount: This line is selecting the month from thebill_datecolumn and the sum of thefine_amountcolumn. TheASkeyword is used to give these selected columns new names (or aliases) for this query. -
FROM bill: This line is specifying the table that we're selecting data from, which is thebilltable. -
WHERE MONTH(bill_date) BETWEEN 7 AND 10: This line is filtering the data so that only rows where the month of thebill_dateis between July (7) and October (10) are included. -
GROUP BY MONTH(bill_date): This line is grouping the selected data by the month of thebill_date, which allows us to calculate the sum of thefine_amountfor each month. -
ORDER BY MONTH(bill_date): This line is ordering the results by the month of thebill_datein ascending order.
Please replace bill_date and fine_amount with your actual column names if they are different.
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:
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.