Can any one help me get the total # of records from a database table, using year?
I have a table – in that I saved the exam date in a date field. I need to get the total # of records from that table using the year only.
I am using mysql.
This is my table
| e_id | int(11) | NO | PRI | NULL | auto_increment |
| exam_name | varchar(50) | NO | | NULL | |
| exam_date | date | NO | | NULL | |
I need to to get the total no of exam held in a particular year only
I think this is what you want? Your question is a little vague though.
SELECT COUNT(*) as 'total' FROM table WHERE DATE_FORMAT(date_field,'%Y') = '2011'tableis the name of your table,date_fieldis the field in your table where the date is stored, and then you can just replace 2011 with whatever year you are trying to search for.