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'.
Question
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'.
Solution 1
Sure, here is the SQL query you asked for:
SELECT AVG(fine_amount) AS average_fine_amount
FROM bills
WHERE YEAR(payment_date) = 2018;
This query works as follows:
-
SELECT AVG(fine_amount) AS average_fine_amount: This part of the query is used to calculate the average of thefine_amountcolumn. TheASkeyword is used to give this average a new name,average_fine_amount. -
FROM bills: This part of the query specifies the table we are selecting data from, which is thebillstable. -
WHERE YEAR(payment_date) = 2018: This is the condition for selecting the data. It selects the rows where the year of thepayment_dateis 2018. TheYEAR()function extracts the year part from a date.
Please note that the actual function to extract the year from a date can vary depending on the SQL dialect you are using. The above query assumes you are using MySQL. If you are using a different SQL dialect, please let me know so I can adjust the query accordingly.
Solution 2
Sure, here is the SQL query you asked for:
SELECT AVG(fine_amount) AS average_fine_amount
FROM bills
WHERE YEAR(payment_date) = 2018;
Here is the step by step explanation:
-
SELECT AVG(fine_amount) AS average_fine_amount: This part of the query is used to calculate the average of thefine_amountcolumn. TheAVGfunction calculates the average. TheASkeyword is used to give an alias name to the result, which isaverage_fine_amountin this case. -
FROM bills: This part of the query specifies the table from which to retrieve the data, which is thebillstable in this case. -
WHERE YEAR(payment_date) = 2018: This is the condition for selecting the rows. TheYEARfunction extracts the year part from thepayment_datecolumn. The condition is that the year must be 2018. So, this query will select the rows from thebillstable where the year ofpayment_dateis 2018, and then calculate the average of thefine_amountfor those rows.
Solution 3
Sure, here is the SQL query you asked for:
SELECT AVG(fine_amount) AS average_fine_amount
FROM bills
WHERE YEAR(payment_date) = 2018;
This query works as follows:
-
SELECT AVG(fine_amount) AS average_fine_amount: This part of the query is used to calculate the average of thefine_amountcolumn. TheASkeyword is used to give a name to the result, which in this case isaverage_fine_amount. -
FROM bills: This part of the query specifies the table from which we want to select data, which in this case is thebillstable. -
WHERE YEAR(payment_date) = 2018: This is the condition that the rows must meet to be included in the average calculation. TheYEARfunction extracts the year part from thepayment_datecolumn, and we only include the rows where this is equal to 2018.
Similar Questions
Write a query to display the standard deviation of the fine_amount whose payment_date is on the year 2018 from bill table. Give an alias name to the standard deviation to the fine amount as 'standard_deviation_amount'.
Write a query to display the average payable_amount from bill table where payable_amount is greater than 10000. Give an alias name to the average payable amount as 'average_payable_amount'.
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'.
Write a query to display the sum of payable_amount whose payment_date is on the year 2018. Give an alias name to the total payable_amount as 'sum_payable_amount'.
Write a query to display the sum of payable_amount with due_date '2017-10-01' from bill table. Give an alias name to the sum of payable amount as 'sum_payable_amount'.
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.