Hi.

I have the SQL query below that works in PostgreSQL.

I am attempting to learn to draw graphs/trend lines to a web page in the 
Django Framework

Rather than use raw SQL queries I would like to learn how to get the same 
results in a Django purists fashion.  I have searched but I cannot find a 
solution or a solution may exist but I do not understand enough to 
recognize.

Is this possible?  If so, how?  

select val, count(*) as valcount
 from (
     select number_1 as val from xscale
     union all
     select number_2 as val from xscale
    union all
     select number_3 as val from xscale
    union all
     select number_4 as val from xscale
    union all
     select number_5 as val from xscale
    union all
     select number_6 as val from xscale
      ) as baseview
 group by val order by valcount desc, val asc;

models.py

from django.db import models

class XScale(models.Model):
    gate = models.TextField(null=False)
    number_1 = models.IntegerField(null=False)
    number_2 = models.IntegerField(null=False)
    number_3 = models.IntegerField(null=False)
    number_4 = models.IntegerField(null=False)
    number_5 = models.IntegerField(null=False)
    number_6 = models.IntegerField(null=False)

    class Meta:
        db_table = u'xscale'

    def __unicode__(self):
        return unicode (self.gate)

Thanks for your help,
Tommy.

-- 
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