Manipulating new generated column

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Manipulating new generated column

Post by Archy »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

I already have the sub total of the row, but I need to get the total of all the rows that are outputted.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's what SUM() does.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

Hmm, yup, just me being stuid : )
Post Reply