Thanks for the suggestion. Unfortunately, unless I'm doing something wrong, this seems to result in just one row being returned showing the sum amount.
Pete Haworth On Nov 15, 2009, at 4:00 AM, [email protected] wrote: > Date: Sat, 14 Nov 2009 14:17:18 -0600 > From: P Kishor <[email protected]> > Subject: Re: [sqlite] Referring to columns named with AS > To: General Discussion of SQLite Database <[email protected]> > Message-ID: > <[email protected]> > Content-Type: text/plain; charset=ISO-8859-1 > > On Sat, Nov 14, 2009 at 1:58 PM, Peter Haworth > <[email protected]> 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? >> > > Try > > SELECT sum(CalcA) AS CalcATotal > FROM ( > SELECT CASE WHEN <condition> THEN <calculation> ELSE <calculation> > END AS CalcA > FROM table > WHERE ... > ) _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

