You are here: Re: number of entries in a date column « PHP SQL « IT news, forums, messages
Re: number of entries in a date column

Posted by Bob Stearns on 10/07/85 11:33

bigsamurai wrote:
> Thanks. I have included the actual query I was running below.
>
> SELECT ood.ood_watch_officer, ood.ood_start, ood.ood_end, ood.ood_date,
> COUNT(ood.ood_date), ood_per.ood_per_no, ood_per.ood_per_name FROM ood,
> ood_per
> WHERE ood.ood_watch_officer=ood_per.ood_per_no
> AND (ood.ood_date BETWEEN '$_POST[date1]' AND
> '$_POST[date2]')
> ORDER by ood_per.ood_per_name";
>
> Two tables ood and ood_per
>
More human readably below. Without a GROUP BY, you are asking for every
every row, so what is COUNT supposed to produce? I believe, in this
case, that it returns 1 every time. If you are trying to produce
intermediate summary lines in a longer report, you need to look into
doing that with your php code or a much fancier bit of sql involving
UNIONs of separate SELECTS for your detail lines and your summary lines.
DB2 has some capabilities in this area which I do not know (yet) how to
use: see ROLLUP and CUBE under GROUP BY. Perhaps your RDMS has some
similar extensions.

SELECT ood.ood_watch_officer, ood.ood_start,
ood.ood_end, ood.ood_date,
COUNT(ood.ood_date), ood_per.ood_per_no,
ood_per.ood_per_name
FROM ood, ood_per
WHERE ood.ood_watch_officer=ood_per.ood_per_no
AND (ood.ood_date BETWEEN '$_POST[date1]' AND
'$_POST[date2]')
ORDER by ood_per.ood_per_name";

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация