我有2个表具有以下结构:
1项目表
如果不存在项目,则创建表格( id bigserial not null主键, group_id整数不为null, 描述文字不为null, …
一个简单的 JOIN 会做:
JOIN
select i.id, h.item_id, h.quantity - u.quantity as quantity from items i join hireds h on h.item_id = i.id where i.quantity < h.quantity order by i.id