Re: how to do SQL SUM

2007-01-14 Thread Honza Král

On 1/14/07, Mark Striebeck <[EMAIL PROTECTED]> wrote:

Hey, that's exactly what I needed too. But when I tried it, I got a

OperationalError: (1140, 'Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
with no GROUP columns is illegal if there is no GROUP BY clause')


my bad... sorry
try
qset.extra( select={ 'sum' : "'SELECT SUM( column ) FROM table'" } )

byt I am afraid that MySQL doesn't support this feature (sub-selects)
until recent versions



I'm using MySQL - maybe I need a different syntax there. But I can easily
use SUM directly in a MySQL client.

  MarkS

On 1/13/07, Honza Kr l <[EMAIL PROTECTED]> wrote:
> On 1/13/07, Picio < [EMAIL PROTECTED]> wrote:
> >
> > Hello,
> > in my custom view, when I retrieve a query set, I need to add (i mean
> > do the sum) of all the values in a column. Is there a built in
> > django-way to do it, instead to write python code myself?
> > In the db_api I saw order_by but I cant see something related to SUM.
> >
> > I know there is .extra method to execute SQL statement but it would be
> > better for me if there is any django built in method to do it.
>
> well the easiest way to do that is
>
> qset.extra( select={ 'sum' : "SUM( column_name )" } )
>
> it will just add an extra field to the result containing the sum.
> There is no "special" way to treat this, nor to specify group by, if
> you need that, you have to drop back to raw sql:
>
>
http://www.djangoproject.com/documentation/model_api/#executing-custom-sql
>
> >
> > I hope It's not a dummy question!
> > Thanks a lot.
> > Picio
> >
> > >
> >
>
>
> --
> Honza Kr l
> E-Mail: [EMAIL PROTECTED]
> ICQ#:   107471613
> Phone:  +420 606 678585
>
>
>
>


 >




--
Honza Kr l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to do SQL SUM

2007-01-14 Thread Mark Striebeck

Hey, that's exactly what I needed too. But when I tried it, I got a

OperationalError: (1140, 'Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
with no GROUP columns is illegal if there is no GROUP BY clause')

I'm using MySQL - maybe I need a different syntax there. But I can easily
use SUM directly in a MySQL client.

 MarkS

On 1/13/07, Honza Král <[EMAIL PROTECTED]> wrote:


On 1/13/07, Picio <[EMAIL PROTECTED]> wrote:
>
> Hello,
> in my custom view, when I retrieve a query set, I need to add (i mean
> do the sum) of all the values in a column. Is there a built in
> django-way to do it, instead to write python code myself?
> In the db_api I saw order_by but I cant see something related to SUM.
>
> I know there is .extra method to execute SQL statement but it would be
> better for me if there is any django built in method to do it.

well the easiest way to do that is

qset.extra( select={ 'sum' : "SUM( column_name )" } )

it will just add an extra field to the result containing the sum.
There is no "special" way to treat this, nor to specify group by, if
you need that, you have to drop back to raw sql:

http://www.djangoproject.com/documentation/model_api/#executing-custom-sql

>
> I hope It's not a dummy question!
> Thanks a lot.
> Picio
>
> >
>


--
Honza Kr l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to do SQL SUM

2007-01-13 Thread Honza Král

On 1/13/07, Picio <[EMAIL PROTECTED]> wrote:


Hello,
in my custom view, when I retrieve a query set, I need to add (i mean
do the sum) of all the values in a column. Is there a built in
django-way to do it, instead to write python code myself?
In the db_api I saw order_by but I cant see something related to SUM.

I know there is .extra method to execute SQL statement but it would be
better for me if there is any django built in method to do it.


well the easiest way to do that is

qset.extra( select={ 'sum' : "SUM( column_name )" } )

it will just add an extra field to the result containing the sum.
There is no "special" way to treat this, nor to specify group by, if
you need that, you have to drop back to raw sql:

http://www.djangoproject.com/documentation/model_api/#executing-custom-sql



I hope It's not a dummy question!
Thanks a lot.
Picio

>




--
Honza Kr l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---