Hi,
I have a data model in django called MainData which was created on top of a table called "my_data". I want to perfom a simple calculation on top of this table via django API. The query is as follow:
select main.id,
sum(main.num - secondary.num) as result
from (select * from my_data
where some_value > 10) as main,
my_data as secondary
where
main.id != secondary.id and
main.a > secondary.a
group by main.id
The MainData model has all the relevant fields (num, id, a and some_value). How can I implement this query via django? (I'm trying to avoid using direct SQL)
Thanks for the help