Im using MySQL server v5.8 as database, how to find median price in query like this:
price_query = Product.objects \
.filter(price_query) \
.annotate(dt=Trunc('StartDate', frequency)) \
.values('dt') \
.annotate(avg_price=Avg('Price'), std_price=StdDev('Price'),
count=Count('Price'), max_price=Max('Price'),
min_price=Min('Price'), median='???') \
.order_by('dt')
response is look like this
{"date":"2021-05-01T00:00:00Z","avg_price":4326.666666666667,"std_price":20.548046676563168,"min_price":4300.0, "max_price":4350.0,"count":3}, {...}, {...}
Any help is highly appreciated.