我有很多列的产品列表,但对我的问题最重要的3个是这些(有一些随机数据):
|--------------------------------------|
| title | category_id | date |
| ----------|-------------|------------|
| Product1 | 1 | 2012-04-18 |
| Product2 | 1 | 0000-00-00 |
| Product3 | 17 | 0000-00-00 |
| Product4 | 17 | 2012-04-10 |
| Product5 | 17 | 2012-04-20 |
| Product6 | 1 | 0000-00-00 |
| Product7 | 2 | 2012-04-20 |
| Product8 | 2 | 0000-00-00 |
| Product9 | 17 | 2012-04-16 |
| Product10 | 22 | 2011-11-26 |
| Product11 | 22 | 2011-12-25 |
| Product12 | 30 | 2012-04-01 |
| Product13 | 2 | 2011-12-31 |
| Product14 | 30 | 2010-05-06 |
|--------------------------------------|具有相同category_id的产品应该一个接一个列出(此时甚至可以通过“ORDER BY category_id”解决),但是我还必须关心date列:category_id和类别内的产品必须按date降序排列(category_id,最新的产品在最上面等等),所以理想情况下结果集应该是这样的(在类别“组”之间增加换行符才更透明):
|--------------------------------------|
| title | category_id | date |
| ----------|-------------|------------|
| Product5 | 17 | 2012-04-20 |
| Product9 | 17 | 2012-04-16 |
| Product4 | 17 | 2012-04-10 |
| Product3 | 17 | 0000-00-00 |
| Product7 | 2 | 2012-04-20 |
| Product13 | 2 | 2011-12-31 |
| Product8 | 2 | 0000-00-00 |
| Product1 | 1 | 2012-04-18 |
| Product2 | 1 | 0000-00-00 |
| Product6 | 1 | 0000-00-00 |
| Product12 | 30 | 2012-04-01 |
| Product14 | 30 | 2010-05-06 |
| Product11 | 22 | 2011-12-25 |
| Product10 | 22 | 2011-11-26 |
|--------------------------------------|是否有可能得到这个结果集只有一个查询,什么是一个工作解决方案?
提前致谢,
马塞尔