=?gb18030?B?u9i4tKO6IFtHRU5FUkFMXSBTUCB0byBjYWxjIHNo?= =?gb18030?B?aXBtZW50cyB2cyByZWNlaXB0cw==?=
От | DDT |
---|---|
Тема | =?gb18030?B?u9i4tKO6IFtHRU5FUkFMXSBTUCB0byBjYWxjIHNo?= =?gb18030?B?aXBtZW50cyB2cyByZWNlaXB0cw==?= |
Дата | |
Msg-id | tencent_6ADF29231CAE28171DE8B7A4@qq.com обсуждение исходный текст |
Ответ на | Re: SP to calc shipments vs receipts (John R Pierce <pierce@hogranch.com>) |
Ответы |
Re: 回复: [GENERAL] SPto calc shipments vs receipts
|
Список | pgsql-general |
hello, is the output calculated by following rule?
on_hand SUM(receipt) - SUM(shipment) - SUM(allocated)
available SUM(receipt) - SUM(shipment)
sql can be:
sum(case when trans_type='REC' then trans_qty when trans_type IN ('SHP', 'ALL') then -trans_qty else 0) as on_hand
sum(case when trans_type='REC' then trans_qty when trans_type = 'SHP' then -trans_qty else 0) as on_hand
but i'm courise about if something is allocated and then it shipped, will you delete the record or allocation?
On 9/23/2013 10:13 PM, Bret Stern wrote:
> I have an inventory transaction table with several fields,
> specifically:
> part_no
> trans_type
> trans_qty
>
> part_no | trans_type | trans_qty
> abc REC 5000 (receipt)
> abc REC 400 (receipt)
> abc SHP 1000 (shipment)
> abc ALL 1000 (allocated)
>
> Looking for the best way to show following totals with SQL
>
> on_hand | allocated | available
> 3400 1000 4400
select part_no,
sum(cast when trans_type='REC' then trans_qty else 0) as
"on_hand",
sum(cast when trans_type='ALL' then trans_qty else 0) as
"allocated",
sum(cast when trans_type='SHP' then trans_qty else 0) as
"allocated"
from inventory_transaction_table
group by part_no;
except, your example output doesn't correlate with your sample input
according to any rules I can see.
--
john r pierce 37N 122W
somewhere on the middle of the left coast
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
.
on_hand SUM(receipt) - SUM(shipment) - SUM(allocated)
available SUM(receipt) - SUM(shipment)
sql can be:
sum(case when trans_type='REC' then trans_qty when trans_type IN ('SHP', 'ALL') then -trans_qty else 0) as on_hand
sum(case when trans_type='REC' then trans_qty when trans_type = 'SHP' then -trans_qty else 0) as on_hand
but i'm courise about if something is allocated and then it shipped, will you delete the record or allocation?
> I have an inventory transaction table with several fields,
> specifically:
> part_no
> trans_type
> trans_qty
>
> part_no | trans_type | trans_qty
> abc REC 5000 (receipt)
> abc REC 400 (receipt)
> abc SHP 1000 (shipment)
> abc ALL 1000 (allocated)
>
> Looking for the best way to show following totals with SQL
>
> on_hand | allocated | available
> 3400 1000 4400
select part_no,
sum(cast when trans_type='REC' then trans_qty else 0) as
"on_hand",
sum(cast when trans_type='ALL' then trans_qty else 0) as
"allocated",
sum(cast when trans_type='SHP' then trans_qty else 0) as
"allocated"
from inventory_transaction_table
group by part_no;
except, your example output doesn't correlate with your sample input
according to any rules I can see.
--
john r pierce 37N 122W
somewhere on the middle of the left coast
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
.
В списке pgsql-general по дате отправления: