Apologies, I omitted what is the real cause of the problem. This simplified SELECT illustrates the error:
SELECT sum( colc * cold ) as total from tst where total > 1000 The error message is "misuse of aggregate: sum()". No error if I remove the where clause. Pete > > Message: 2 > Date: Sat, 22 Oct 2011 17:38:23 +0100 > From: Simon Davies <simon.james.dav...@gmail.com> > To: General Discussion of SQLite Database <sqlite-users@sqlite.org> > Subject: Re: [sqlite] Question re use of column alias in SELECT > Message-ID: > <CANG6AhTGUUk0UwoZoYtqQEtfVPU+AxYOhU5SFnetW=skjgy...@mail.gmail.com > > > Content-Type: text/plain; charset=ISO-8859-1 > > On 22 October 2011 17:28, Pete <p...@mollysrevenge.com> wrote: > > If I have a SELECT statement like: > > > > SELECT cola, colb, sum(tableb.colc * tableb.cold) AS Total FROM TableA > GROUP > > BY cola ORDER BY Total > > What is tableb? > > > > > ...I get an error, I think because of referring to Total in the ORDER BY > > clause. ?Is it not possible to refer to column aliases anywhere within a > > SELECT statement other than in the AS clause? ?If not, is there any other > > way to achieve this without repeating the sum expression? > > sqlite> create table tst( id integer primary key, cola integer, colb > integer, colc integer, cold integer ); > sqlite> SELECT cola, colb, sum( colc * cold ) as total from tst group > by cola order by total; > > works for me, so I don't think that the alias is your problem. > > > > > Pete > > Regards, > Simon > > > ******************************************** > > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users