我想使用SQLAlchemy复制Excel的VLookUp函数。例如,如果我有以下两个表:
Department:
1. Sales
2. Sales
3. Sales
4. Sales
Category:
1. Sales Level 1
我希望能够创建:
1. Sales Level 1
2. Sales Level 1
3. Sales Level 1
4. Sales Level 1
然而,我现在得到:
1. Sales Level 1
2. Sales None
3. Sales None
4. Sales None
以下是我编写的脚本的简化版本:
data = Department.query.outerjoin(Category, Deparment.Name==Category.Name).add_columns(Category.Level).all()
我没有将列Category.Name
设置为Deparment.Name