prattom
prattom

Reputation: 1753

Group results by days in a date range

I have a table in which one of the column is timestamp and I have the following query

SELECT * FROM test WHERE (timepacket BETWEEN 2014-02-16 00:00:00 and 2014-02-19 00:00:00) AND (shift = 1)

But this query gives me all the rows between the date range given in sql query. Thus my question is how can group the results from above query according to dates. Like

2014-02-16

1st row

2nd row

3rd row

2014-02-17

1st row

2nd row

3rd row

4th row

and so on

Upvotes: 0

Views: 71

Answers (3)

Zafar Malik
Zafar Malik

Reputation: 6854

Even your query is not much clear but as per my understanding you want to do ordering based on date, if it is then use below query-

SELECT * FROM test WHERE (timepacket BETWEEN 2014-02-16 00:00:00 and 2014-02-19 00:00:00) AND shift = 1 order by date(timepacket);

Upvotes: 0

Nagaraj S
Nagaraj S

Reputation: 13484

Use GROUP BY or Order by

SELECT * FROM test WHERE (timepacket BETWEEN 2014-02-16 00:00:00 and 2014-02-19 00:00:00)
 AND (shift = 1) GROUP BY timepacket

Upvotes: 0

Abdul Manaf
Abdul Manaf

Reputation: 4888

SELECT * FROM test WHERE 
timepacket BETWEEN '2014-02-16 00:00:00' AND '2014-02-19 00:00:00' 
AND shift = 1 
GROUP BY timepacket;

Upvotes: 0

Related Questions