【发布时间】:2021-11-25 11:08:50
【问题描述】:
我有两个表,它们只包含相同的产品 ID,并且它们没有外键。所以问题是关于我如何在查询中通过 id 过滤它们。 在 SQL 中,我想做这样的事情
SELECT Url FROM pricehistory p INNER JOIN product d ON p.ProductID = d.ProductID
模型如下所示:
class Product(models.Model):
ProductID = models.CharField(..)
Price = models.FloatField(..)
Url = models.CharField(..)
....
class PriceHistory(models.Model):
ProductID = models.CharField(..)
Price = models.FloatField(..)
Retailer = models.CharField(..)
Timestamp = models.DateTimeField(..)
【问题讨论】:
-
请分享您的模型。
-
这里是.....
-
Product模型上的ProductID是主键吗?为什么 PriceHistory 上的 ProductID 列未定义为 Product 模型的 ForeignKey?