Re: newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?
| From: | Chris | Date: | Tue, 04 Aug 2009 01:11:59 +0000 |
| Subject: | Re: newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column? | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46396@lists.php.net to get a copy of this message | ||
Chris wrote:
Ben Dunlap wrote: ...which will echo:I should have given an example .. select count(*) as record_count, date(column_name) as date_field, 'my_table' as table_name union all select count(*) as record_count, date(column_name) as date_field, 'my_table_2' as table_name and end up with:.. and a field describing which table it came from, otherwise you end up with: count | date ------------"<tr><td>#records in 't7solar_landing' matching the given (iterating) date (in the 'solarLandingDateTime' column)</td><td>#records in 'aw_7solar_confirm' matching the given (iterating) date (in the 'solarAwConfDateTime' column)</td><td>#records in 'aw_7solar_aw' matching the given (iterating) date (in the 'solarAWDateTime' column)</td></tr>"...If you just need to count the records with a particular date you should be able to use this construction: SELECT COUNT(*) ASrecord_count,DATE(<date_column>) ASFROM <table> GROUP BYdate_fielddate_fieldYou could probably write a generalized PHP function (called 'build_query()' or something) that would construct this query given a table name and a date-column name, and call it once for each table/column pair. Then you could stitch the three query strings together, in PHP, into one large query using SQL's "UNION ALL", which concatenates the results of multiple queries into one large result-set: (<query 1>) UNION ALL (<query 2>) UNION ALL (<query 3>) And then pass that one large query to the database.5 | 2009-01-01 10 | 2009-01-01and no reference point.
count | date | table_name-------------------------------
5 | 2009-01-01 | table 1 10 | 2009-01-01 | table 2-- Postgresql & php tutorials http://www.designmagick.com/