嵌套SELECT与INNER JOIN

时间:2014-11-09 18:20:15

标签: python sql django

我已收到此model.py个文件:

from django.db import models
from django.contrib.auth.models import User


class Vehicle(models.Model):
    user = models.ForeignKey(User)
    name = models.CharField(max_length=30)
    omei = models.FloatField(max_length=16)

def __str__(self):
    return self.name


class LatLong(models.Model):
    vehicle = models.ForeignKey(Vehicle)
    lat = models.FloatField()
    long = models.FloatField()
    date = models.DateField()

def __str__(self):
    return str(self.lat)+str(" ")+str(self.long)

鉴于三个输入time1time2omei,我想要一组介于LatLongstime1之间的time2引用具有给定omei的车辆。

据我所知,有两种方法:使用嵌套SELECT或使用INNER JOIN

这些方法的权衡是什么?

1 个答案:

答案 0 :(得分:0)

试试这个:

latlongs = LatLong.objects.filter(date__gte=time1, date__lte=time2, vehicle__omei=omei)