Page 1 of 1

Manipulating new generated column

Posted: Fri Mar 18, 2005 6:05 am
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.

Posted: Fri Mar 18, 2005 8:11 am
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()

Posted: Fri Mar 18, 2005 8:15 am
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.

Posted: Fri Mar 18, 2005 8:43 am
by feyd

Code: Select all

... SUM(item.qty * item.price) ...

Posted: Fri Mar 18, 2005 9:00 am
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.

Posted: Fri Mar 18, 2005 10:01 pm
by feyd
that's what SUM() does.

Posted: Sat Mar 19, 2005 6:13 pm
by Archy
Hmm, yup, just me being stuid : )