On Sat, 14 Nov 2009 11:58:42 -0800, Peter Haworth <p...@mollysrevenge.com> wrote:
>I'm trying to get a SELECT statement in the following general form to >work: > >SELECT CASE WHEN <condition> THEN <calculation> ELSE <calculation> >END AS CalcA, sum(CalcA) AS CalcATotal .... > >I get an error "no such column" referring to CalcA when used in the >sum function. I'm trying to get total of all the values of CalcA >across all the selected rows. Is there a way to do this? You can't combine the two, because sum() is an aggregate function. There is a way to show the CalcA values together with their sum though: SELECT 'detail' AS Descr, CASE WHEN <condition> THEN <calculation> ELSE <calculation> END AS CalcA; UNION SELECT 'total' AS Descr sum( CASE WHEN <condition> THEN <calculation> ELSE <calculation> END ) AS CalcA; (untested) -- ( Kees Nuyt ) c[_] _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users