reena.sharam
reena.sharam

Reputation: 135

Mysql fetch data with count and between date

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.

enter image description here

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

Answers (3)

Nisar
Nisar

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

Jeyachandran Rathnam
Jeyachandran Rathnam

Reputation: 314

try :

Select zip, count(*) from table_name where created between 'from_date' and 'to_date' group by zip

Upvotes: 1

Trav L
Trav L

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

Related Questions