Re: summing data within a table
| From: | php3 at developersdesk dot com | Date: | Tue, 03 Oct 2000 05:09:24 +0000 |
| Subject: | Re: summing data within a table | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-3245@lists.php.net to get a copy of this message | ||
Addressed to: "Mark McCray" <mm@tbwachiat.com>
php-db@lists.php.net
** Reply to note from "Mark McCray" <mm@tbwachiat.com> Mon, 02 Oct 2000 21:29:35
-0400
>
> should this work in mysql, cause it's saying that I have an error near
> the 'GROUP BY section of the statement. Marky
>
I did not actually try it, but I've done similar things before. Try
reversing the GROUP BY and ORDER BY clauses.
I know this one works:
SELECT COUNT(*) AS Count, Category
FROM Responses, Categories
WHERE Responses.CategoryID = Categories.CategoryID
GROUP BY Category
ORDER BY Count DESC;
I just copied it from one of my web pages.
> > From: php3@developersdesk.com
> > Reply-To: php3@developersdesk.com
> > Date: Mon, 2 Oct 2000 18:34:35 MST
> > To: "Mark McCray" <mm@tbwachiat.com>, php-db@lists.php.net
> > Subject: Re: [PHP-DB] summing data within a table
> >
> > Addressed to: "Mark McCray" <mm@tbwachiat.com>
> > php-db@lists.php.net
> >
> > ** Reply to note from "Mark McCray" <mm@tbwachiat.com> Mon, 02 Oct 2000
> > 20:10:29 -0400
> >>
> >> Hey all, I'm not sure how to go about this, but here goes:
> >>
> >> I have one table, it's sort of like an invoice items table.
> >>
> >> It's made up of employees, dates, and amounts.
> >>
> >> How do I summarize all the different items belonging to each employee and
> >> sum their amounts.
> >>
> >> so if I have:
> >>
> >> 1-1-2000 Mark 2000.00
> >> 1-1-2000 Debbie 3000.00
> >> 1-4-2000 Lenny 3050.89
> >> 2-8-2000 Mark 1500.00
> >> 2-24-2000 debbie 2000.00
> >> 3-3-2000 Lenny 8000.00
> >>
> >> How do I make a summary where it shows:
> >>
> >> Mark totals 4500.00
> >> Debbie totals 5000.00
> >> and
> >> Lenny totals 11050.89
> >>
> >> I think this might be db 101, but I'm a little fuzzy on it. Marky
> >
> >
> > SELECT Name, SUM( Amount ) AS Sum FROM Table ORDER BY Name GROUP BY Name;
> >
> >
> >
> >
> >
> > Rick Widmer
> > Internet Marketing Specialists
> > www.developersdesk.com
> >
>
>
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com