Hello,

I'd like to use some MySQL function in a query from django, because the 
YEARWEEK() & INTERVAL constructs of mysql are interesting to me for 
efficiently aggregating entries per week. Is there any way to include it in 
the Select of the django query... or do I have to resort to raw() call?

Thanks in advance!

fyi the whole SQL query would be something similar to
*SQL = """    SELECT 
            YEARWEEK( `datetime` - INTERVAL 7 DAY , 7 ) AS `yearWeek` , 
            COUNT( IF( `thdFinal` = 1, 1, NULL ) ) AS `finalsCount` , 
            COUNT( IF( `id` = `thdRoot_id` , 1, NULL ) ) AS `rootsCount` , 
            COUNT( * ) AS `mailsCount` ,
            `project_id`,
            FROM `data_mail`
            WHERE `project_id` = %s  
            GROUP BY `yearWeek`  
        """ *

and if I don't find anything more "djangoïc" I'd resort to 

*from django.db import connection
cursor = connection.cursor()
cursor.execute(SQL, [project_id])*

My reason to use YEARWEEK and a relate GROUP BY is because this seems the 
most efficient way to aggregate time entries over a week, instead of a 
double comparison using datetime functions... and I got a huge database.

any idea is welcome, thanks again,
Bertrand.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to