我有三个表
Item master:存储item master的详细信息
id integer NOT NULL DEFAULT, primary key
name character varying(255),
description character(255),
price double precision,
tax double precision,
readytosales character(1) DEFAULT 'N'::bpchar,
itemgroupid integer,
uom character varying(30),
quantity double precision DEFAULT 0,
purchase:商店购买明细
purchaseid integer NOT NULL DEFAULT,
quantity double precision DEFAULT 0,
purchasemasterid integer NOT NULL,
itemid integer NOT NULL,
itemprice double precision DEFAULT 0.00,
sales:店铺销售明细
salesid integer NOT NULL DEFAULT,
quantity double precision DEFAULT 0,
salesmasterid integer NOT NULL,
itemid integer,
itemprice double
用于获取股票摘要的公式是
itemmaster.quantity + purchase.quantity -sales.quantity
我使用下面的查询来获取详细信息,但无法获取结果
select im.id as itemid,
name as itemname,
im.quantity as oepningquantity,
im.price as openingprice,
(im.quantity * im.price) as openingbalance,
p.quantity as purchasequantity, p.itemprice as purchaseprice,
(p.quantity * p.itemprice)as totalpurchaseprice,
s.quantity as salesquanity, s.itemprice as saleprice,
(s.quantity *s.itemprice)as totalsalesprice
from item_master as im
full outer join purchase as p on im.id=p.itemid
full outer join sales as s on im.id=s.itemid
最佳答案
您的查询有一个小问题。 正确的查询是:
select im.id as itemid,
name as itemname,
im.quantity as oepningquantity,
im.price as openingprice,
(im.quantity * im.price) as openingbalance,
p.quantity as purchasequantity, p.itemprice as purchaseprice,
(p.quantity * p.itemprice)as totalpurchaseprice,
s.quantity as salesquanity, s.itemprice as saleprice,
(s.quantity *s.itemprice)as totalsalesprice
_____from item_master as im ______ ------This Statement is Wrong.
from item_master -- Try This One.
full outer join purchase as p on im.id=p.itemid
full outer join sales as s on im.id=s.itemid
关于sql - 如何在postgresql中连接3个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53707895/