On Wed, 24 Jul 2013 11:38:42 +0530, Sandeep kaur <mkaurkhalsa@gmail.com>
declaimed the following:
>Suppose I have following table in my database :
>
>activity1 | activity2 | activity3 | activity4 | activity5
>6 | 7 | 5 | 9 | 8
>
>The first row are the field names and the second row are the data
>entries. How can I get 3 maximum values out of each row of this table?
>Like from this row, I should get 7,8,9.
>Eagerly waiting fro your reply.
Well, I'd start by normalizing that... One should not have repeating
groups in a relational database; it is often easier to extract data when
the "column name" is treated as a key in a two column table
Activity_Order | Activity_Value
1 | 6
2 | 7
3 | 5
4 | 9
5 | 8
Then one can do something like (SQL, not Django ORM)
select Activity_Order, Activity_Value from Activities
order by Activity_Value desc
limit 3
(works with SQLite3)
"4","9"
"5","8"
"2","7"
Granted, to really be useful, you'll need a foreign key linking back to
the parent record:
primarykey|some|stuff|related|to|activity1|activity2|activity3|...
=>
primarykey|some|stuff|related|to
and
fkeytoprimarykey|activityorder|activityvalue
...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
--
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+unsubscribe@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.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment