我是新来的,我不知道如何加入。 我有以下模式和相应的表格:
class ModelA(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=30)
class ModelB(models.Model):
id = models.AutoField(primary_key=True)
a_id = models.ForeignKey(ModelA, on_delete=models.CASCADE)
c_id = models.ForeignKey(ModelC, on_delete=models.CASCADE)
extra = models.CharField(max_length=30)
class ModelC(models.Model):
id = models.AutoField(primary_key=True)
number = models.CharField(max_length=30)
ModelA -> Table a: id, name
ModelB -> Table b: id, a_id, c_id, extra
ModelC -> Table c: id, number
我愿借此机会加入:
SELECT a.*, b.extra, c.number
FROM a
LEFT JOIN b ON a.id = b.a_id
LEFT JOIN c ON c.id = b.c_id
我不知道如何这样做,或者甚至可能这样做。