MySQL date result split by date
I have a query that show results of projects being worked between 2 dates. I would like the results to show me something like this
For: 2011-07-11
- Result 1
- Result 2
- Result 3
For: 2011-07-12
- Result 4
- R开发者_Python百科esult 5 etc...
So it's showing me the results split by date. Is that possible with a MySQL query ? Or I will need to make a query for each date ?
Thanks
So there really isn't a way to make this sort of query 'classy' if you're going to be pulling all of the information from a single query. You can't make anything other than a rectangular table and therefore can't represent many-to-one, one-to-many, or many-to-many relationships in a classier way. If you want to do something like this I would recommend using a server-side scripting language to take care of it for you and display it however you want (that is unless this isn't a web-based application, then just use a non-web language).
In order to pull all the data and group/sort by the date, you would do the following:
SELECT *
FROM myDB.myTable
GROUP BY theDateValue
ORDER BY theDateValue ASC;
This will pull all records from the table, group them by their relevant dates, and then sort them in ascending order by the date value(s).
Most of what your asking can be done in the presentation layer of your application. You could use a tree control, or a grid/table with grouping etc to present the data as a Heading-Sub Heading or Master-Detail layout. You would need to iterate over the records returned and then group them in the desired manner.
精彩评论