I have a table containing the fields "original_price" and
"discounted_price". I want to order the results of an SQL statement
according to the relative discount which is: (original_price-
discounted_price)/original_price.

So I wrote the following SQL statement:
SELECT id, name FROM offers_offer ORDER BY (original_price-
discounted_price)/original_price
and found out it was not sorting them properly.
I then tried directly in sqlite3 and found out that the operation
(original_price-discounted_price)/original_price was actually
returning 0 whenever the prices (original and discounted) were
integers even tough in the database they are defined as floats. The
sorting was correct when I was putting a decimal price in any of the
two fields.

Any suggestion on how to get around this problem?

Maybe this could be solved using the django api instead of the
standard django.db.connection? The problem I faced when trying to use
django was the ordering.
In the api documentation it is specified that I can do ordering like
Offers.objects.order_by('field_name')
but what I wanted to use was something like
(original_price-discounted_price)/original_price instead of
'field_name', but django doesn't allow this statement.

Many thanks
Francesco


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to