|
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]
|