Left Join multiple tables on a parent table and subtract one column from the parent table
Left Join multiple tables on a parent table and subtract one column from the parent table
我有 3 个 table(donor_detail
、items
和 store
)加入了 1 个父 table(donated_items
), 现在父级 table 中有一列 quantity
我想从另一个 table 的列中减去,即 issued_donation.issued_quantity
这是我的 SQL 左连接但我不明白我应该如何减去该列。即 donated_items.quantity
- issued_donation.issued_quantity
SELECT t1.*, t2.donor_name,t2.ID, t3.ID,t3.item_name, t4.store_name, t4.ID
FROM donated_items as t1
LEFT JOIN donor_detail as t2 ON t1.donor_id = t2.ID
LEFT JOIN items as t3 ON t1.item_id = t3.ID
LEFT JOIN stores as t4 ON t1.store_id = t4.ID
你的问题不是很清楚,但我怀疑你是在谈论减去值,而不是列。如果我是对的,您必须加入其他 table (issued_donation
),然后您可以向所选字段添加类似 t1.quantity - t5.issued_quantity AS remainingQuantity
.
的内容
我有 3 个 table(donor_detail
、items
和 store
)加入了 1 个父 table(donated_items
), 现在父级 table 中有一列 quantity
我想从另一个 table 的列中减去,即 issued_donation.issued_quantity
这是我的 SQL 左连接但我不明白我应该如何减去该列。即 donated_items.quantity
- issued_donation.issued_quantity
SELECT t1.*, t2.donor_name,t2.ID, t3.ID,t3.item_name, t4.store_name, t4.ID
FROM donated_items as t1
LEFT JOIN donor_detail as t2 ON t1.donor_id = t2.ID
LEFT JOIN items as t3 ON t1.item_id = t3.ID
LEFT JOIN stores as t4 ON t1.store_id = t4.ID
你的问题不是很清楚,但我怀疑你是在谈论减去值,而不是列。如果我是对的,您必须加入其他 table (issued_donation
),然后您可以向所选字段添加类似 t1.quantity - t5.issued_quantity AS remainingQuantity
.