我试图在django的ORM中翻译一个SQL查询.试图使用annotate()但我没有设法获得与sql查询相同的结果.
这是我的模特:
class Fuel(models.Model):
type = models.CharField(max_length=150)
class Station(models.Model):
name = models.CharField(max_length=150, null=True)
class Price(models.Model):
fuel_type = models.ForeignKey(Fuel)
station = models.ForeignKey(Station)
price = models.FloatField()
date = models.DateTimeField('Date', auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)
这是我尝试在django中翻译的查询:
select * from myapp_price where id IN ((select max(id) from myapp_price where station_id=121600 group by fuel_type_id));
Run Code Online (Sandbox Code Playgroud)
这可能吗 ?