sorting mysql result datas
for example i have a table which looks like :
id | date | ...
- 20.07.2011
- 20.07.2011
- 20.07.2011
- 20.07.2011
- 21.07.2011
- 21.07.2011
- 21.07.2011
- 21.07.2011
- 25.07.2011
- 25.07.2011
- 25.07.2011
- 25.07.2011
- 25.07.2011
- 25.07.2011
- 25.07.2011
- 31.07.2011
- 31.07.2011
- 31.07.2011
- 02.08.2011
- 02.08.2011
- 02.08.2011
- 02.08.2011
- 02.08.2011
- 02.08.2011
- 02.08.2011
- 02.08.2011
how i can get each date and ids for each date in easiest way ( maybe only with a query )
i need something like :
20.07.2011 {1,2,3,4}
21.07.2011 {5,6,7,8}开发者_如何学JAVA
25.07.2011 {9,10,11,12,13,14,15}
31.07.2011 ...
02.08.2011 ...
SELECT `date`, GROUP_CONCAT(`id`) FROM `example` GROUP BY `date`
GROUP_CONCAT on MySQL docs
You can append/preppend curly braces and sperate the id's how you like it. Just look at the docs.
select `date`, group_concat(`id`) from `table` group by `date`
精彩评论