Peter Haworth wrote:
> Interesting you should classify my data need as a waste without
> knowing anything about my application.  What if I want to calculate a
> percentage that the first column is of the total - would it still be a
> waste to calculate the total?

Yes, it would be a waste to calculate the total over and over. You could run a 
query with sum() once, save the result in a program variable, then do something 
like

select col, col / :total as percentage from mytable;

and bind the result of the previous query to :total parameter.

Try this though:

select col, colTotal
from mytable, (select sum(col) as colTotal from mytable);

I'm not sure, but it's possible this query calculates the sum only once. The 
one I suggested before, namely

select col, (select sum(col) from mytable) as colTotal
from mytable;

almost certainly calculates the sum once for each row.

Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to