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, sqlite-users-requ...@sqlite.org wrote:

> Date: Sat, 14 Nov 2009 14:17:18 -0600
> From: P Kishor <punk.k...@gmail.com>
> Subject: Re: [sqlite] Referring to columns named with AS
> To: General Discussion of SQLite Database <sqlite-users@sqlite.org>
> Message-ID:
>       <cdf6db500911141217l646bd815s8f2b7f1ad98fc...@mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Sat, Nov 14, 2009 at 1:58 PM, 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?
>>
>
> 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
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to