I think that you can get all your table data on a Django View and then make
an algorithm to have your data, maybe using a recursive function.

Like i understand you are putting together every single field in one... so
your first result its one field (val) then you are counting all similar
value, so
1- create an array and get all number_1
2- append to previus object all number_2
3- repeat for every field
4- order ascending or descending the array
5- take first element and compare with others and count equal values and
then delete that counted value (this reduce the extention of your array)
6- move one position and repeat and proced, like point 5, from them.
7- do that to the last element in the array....
This is a quick aproach... but you have an idea now. You can do it better
than me.

I dont say that is the best choice... maybe for this particulary example
using the store procedure its better ( for the health of the server cpu :P )

I dont know if python or django have a function to resolve your
requirements.

See ya


2013/4/10 Tommy <tom...@gmail.com>

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



-- 
Rafael E. Ferrero
Claro: (03562) 15514856

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