Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 2 columns in mysql database i.e. totalRating and ratingDate. There exists multiple values of totalRating against on date e.g. there can be 5 totalRatings on date 2016-08-29, 4 on 2016-08-30. I am using ChartJs to show a graph of totalRating and ratingDate. I want to take the average of totalRatings of a single date and plot it on graph i.e. one totalRating for one date. I am using PHP for the backend. Can somebody help me with the queries?
Using below query you can find average rating for all dates.
select AVG(totalRatings) as avgRating, date from YOUR_TABLE group by date;
I think what you need is the AVG mysql function, your query should be something like:
select AVG(totalRatings) from YOUR_TABLE where date=YOUR_DATE;
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a mysql record with the columns start_date and end_date. Now I have a date (as example 2017-08-03) and i want to ask if this date is between the start_date and end_date in my mysql table.
Is this possible?
Use between:
SELECT * FROM events
WHERE '2012-01-18' between start_date AND end_date
BTW: Take care of time part if start and end are datetime types
You can use this:
SELECT * FROM events
WHERE start_date<='2012-01-18'
AND end_date>='2012-01-18'
SELECT *
FROM `yourtable`
WHERE (your_found_date BETWEEN 'start_date' AND 'end_date')
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to display a database record between two date ranges using PHP-mysql.
I am working on a project in which employees payment record is saved in a table. I want to see what amount has been paid between two dates selected through date-picker.
Try this:
SELECT amount FROM mytable WHERE created_at BETWEEN '2011-12-01' AND '2011-12-07';
Assuming mytable to be the table name, created_at to be the date field and amount to be the amount field.
Hope this helps.
Peace! xD
SELECT amount FROM mytable
WHERE
created_at >= '2011-12-01'
AND
created_at <= '2011-12-07';
If you need the sum of the salary between two dates you can do somethig like:
SELECT sum(salary) as total FROM table_name
WHERE job_date BETWEEN 'dd-mm-yyyy' AND 'dd-mm-yyyy';
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Is it possible to calculate the average of data retrieved from mysql database on basis of date. For example records are saved in database on daily basis with storing its date the average method will calculate overall average but can it be possible to calculate on basis of date stored in database
You can group records by date and calculate average of a column.
Example:
SELECT date, AVG(column_name)
FROM tbl_name
GROUP BY date;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a DataTable which has 5 columns:
sl, Doctor, Appointments, fees
The DataTable contains 4 rows.
I want to show the sum of the fees Column as "Total fees"
What is the best way of doing this?
If you are using DataTable plugin to show tables, then try it to calculate sum
var table = $('#example').DataTable();
table.column( 4 ).data().sum(); // as fees is your fourth column
More Info:
http://www.datatables.net/plug-ins/api/sum()#
https://datatables.net/examples/plug-ins/api.html
For normal database operation try simple query using SUM aggregate method
SELECT SUM(fees) as 'Total fees' FROM your_table_name
You need use the SUM() function. If your table name is DataTable this is your query:
SELECT SUM(fees) as 'Total fees' FROM DataTable
Read more at:
http://www.tutorialspoint.com/mysql/mysql-sum-function.htm
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm making a little voting tool (voting from 1 to 5) and I have the votes stored in a DB. I'm wondering, what is the best manner to count all the rows (of a specific post ID) and then calculate the sum of those specific rows so that I can display the results.
i.e
Results: 3.5 / 5
(total votes: 1047)
Should I use a PHP loop or MYSQL sum?
SELECT AVG(vote), COUNT(vote) FROM vote_table WHERE post_id = 1234;
The first. column gives your average out of 5 and the count the total votes. To get all the stats at once:
SELECT AVG(vote), COUNT(vote), post_id FROM vote_table GROUP BY post_id;