1
我有幾張如下所示的表,我想加入不是外鍵到對方表的列,然後有權訪問兩個列。下面是類:使用SQLAlchemy和檢索所有列在Flask中的多個非外鍵列上連接2個表
class Yi(db.Model):
year = db.Column(db.Integer(4), primary_key=True)
industry_id = db.Column(db.String(5), primary_key=True)
wage = db.Column(db.Float())
complexity = db.Column(db.Float())
class Ygi(db.Model, AutoSerialize):
year = db.Column(db.Integer(4), primary_key=True)
geo_id = db.Column(db.String(8), primary_key=True)
industry_id = db.Column(db.String(5), primary_key=True)
wage = db.Column(db.Float())
所以,我想獲得通過的ID加入兩個表的列我指定,在這種情況下,新年和industry_id。這可能嗎?下面是我寫來實現這一目標的SQL ...
SELECT
yi.complexity, ygi.*
FROM
yi, ygi
WHERE
yi.year = ygi.year and
yi.industry_id = ygi.industry_id