Reputation: 135
This is my table structure. I have to fetch the zip_code's range as per they created in database table in given between date.
For example in the given between dates are 4-aug-14 to 9-aug-14 i need follwing result
zip number
90620 10
90621 5
How i write mysql query for this.
Upvotes: 2
Views: 197
Reputation: 6038
IS this you want the result DEMO
try
SELECT zip
, COUNT(1) AS count
FROM table1
WHERE created BETWEEN '2014-08-04 00:00:00' AND '2014-08-08 23:59:59'
GROUP BY zip
ORDER BY count DESC
Upvotes: 2
Reputation: 314
try :
Select zip, count(*) from table_name where created between 'from_date' and 'to_date' group by zip
Upvotes: 1
Reputation: 15192
Try this:
SELECT zip
, COUNT(id) AS count
FROM [table]
WHERE created BETWEEN '2014-08-04 00:00:00' AND '2014-08-08 23:59:59'
GROUP BY zip
ORDER BY count DESC
Upvotes: 1