Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Fri Mar 18, 2005 6:05 am
My SQL query creates a new column from supplied data - quantity, and cost of item, so you are left with the generated column subTotal. However, I cannt refer to this column to do anything with it - I want to add up all of the subTotal columns and produce a total at the bottom.
Does anyone know of how I could do this?
Thanks.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 18, 2005 8:11 am
why can't you refer to the column? If it's apart of the table structure you can reference it all you like. If it's faked, then you can supply the calculation to a grouping function like SUM()
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Fri Mar 18, 2005 8:15 am
Well, at the moment, I have the quantity, and the the price in the table at the moment, and I generate the subTotal by using:
item.qty*item.price AS subTotal
However, whenever I try and make reference to subTotal as a column, it just says that the column cannot be found.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 18, 2005 8:43 am
Code: Select all
... SUM(item.qty * item.price) ...
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Fri Mar 18, 2005 9:00 am
I already have the sub total of the row, but I need to get the total of all the rows that are outputted.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 18, 2005 10:01 pm
that's what SUM() does.
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Sat Mar 19, 2005 6:13 pm
Hmm, yup, just me being stuid : )