Re: How can I create a sequence number for a data set in the model?
On Fri, 6 Apr 2012 22:34:35 -0700, Mark Phillips
<mark@phillipsmarketing.biz> declaimed the following in
gmane.comp.python.django.user:
>
> Basically, I have sets of data determined by a foreign key, and I want to
> know the order in which the rows arrive within a data set.
>
IOWs, you don't really need a value incrementing per foreign key...
After all, the primary key already reflects the /order/ of new data
inserts.
In plain SQL, this might be an application for a "group by" the
foreign key, "order by" the primary key. Note that your example is NOT
very clear. "Reset to zero" could result in:
1 1 1 ....
2 1 2 ...
3 2 1 ...
4 1 1 ...
5 2 1 ...
6 2 2 ...
Whereas, ignoring the example "sequence" column, group by/order by
would return
1 1 1 ...
2 1 2 ...
4 1 1 ...
3 2 1 ...
5 2 1 ...
6 2 2 ...
Actually, just an ORDER BY FK, PK would produce the above... GROUP
BY would be used if you need something like counts/avg for each FK set.
--
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 post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home