I have table named comments:
ID | COMMENT | DATE |
---|---------|----------|
1 | TEXT... | 01/01/12 |
2 | TEXT... | 01/01/12 |
3 | TEXT... | 15/01/12 |
4 | TEXT... | 01/01/13 |
In the table there are comments from 2012 and few from 2013. How can I select only records from 2012 and then get average comment count of 2012?
One really shouldn’t store temporal values in string-type columns. I suggest that you first convert your DATE column to MySQL’s
DATEtype:(Obviously you will need to update your application code to use this new column).
Then:
You can simply use the inequality operators in a filter:
Not entirely sure what you mean by “average comment count”, but if you want the mean number of comments per day: