- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有特定的任务,但不知道如何实现它。我希望有人能帮助我 =)
我有 stock_move 表:
product_id |location_id |location_dest_id |product_qty |date_expected |
-----------|------------|-----------------|------------|--------------------|
327 |80 |84 |10 |2014-05-28 00:00:00 |
327 |80 |84 |10 |2014-05-23 00:00:00 |
327 |80 |84 |10 |2014-02-26 00:00:00 |
327 |80 |85 |10 |2014-02-21 00:00:00 |
327 |80 |84 |10 |2014-02-12 00:00:00 |
327 |84 |85 |20 |2014-02-06 00:00:00 |
322 |84 |80 |120 |2015-12-16 00:00:00 |
322 |80 |84 |30 |2015-12-10 00:00:00 |
322 |80 |84 |30 |2015-12-04 00:00:00 |
322 |80 |84 |15 |2015-11-26 00:00:00 |
即它的产品表从一个仓库移动到第二个仓库。
如果我使用这样的东西,我可以在自定义日期计算库存:
select
coalesce(si.product_id, so.product_id) as "Product",
(coalesce(si.stock, 0) - coalesce(so.stock, 0)) as "Stock"
from
(
select
product_id
,sum(product_qty * price_unit) as stock
from stock_move
where
location_dest_id = 80
and date_expected < now()
group by product_id
) as si
full outer join (
select
product_id
,sum(product_qty * price_unit) as stock
from stock_move
where
location_id = 80
and date_expected < now()
group by product_id
) as so
on si.product_id = so.product_id
结果我有当前库存:
Product |Stock |
--------|------|
325 |1058 |
313 |34862 |
304 |2364 |
但是如果我每月需要库存怎么办?是这样的吗?
Month |Total Stock |
--------|------------|
Jan |130238 |
Feb |348262 |
Mar |2323364 |
如何计算每个月开始到月底的产品数量?
我只有一个想法——每个月使用 24 个子查询获取库存(例如下面)
Jan |Feb | Mar |
----|----|-----|
123 |234 |345 |
在此旋转行和列之后结束?我认为这很愚蠢,但我不知道另一种方式......请帮助我 =)
最佳答案
这样的东西可以为您提供每月“结束”库存快照。诀窍是您的数据可能会省略某些部分的某些月份,但该部分仍然会有余额(即 1 月份收到 50 个,2 月份没有发生任何事情,但您仍然希望显示 2 月份的总数为 50)。
处理此问题的一种方法是提出所有可能的组合部分/日期。在此示例中,我假设 1/1/14 + 24 个月,但这在 all_months
子查询中很容易更改。例如,您可能只想从 stock_move
表中的最小日期开始。
with all_months as (
select '2014-01-01'::date + interval '1 month' * generate_series(0, 23) as month_begin
),
stock_calc as (
select
product_id, date_expected,
date_trunc ('month', date_expected)::date as month_expected,
case
when location_id = 80 then -product_qty * price_unit
when location_dest_id = 80 then product_qty * price_unit
else 0
end as qty
from stock_move
union all
select distinct
s.product_id, m.month_begin::date, m.month_begin::date, 0
from
stock_move s
cross join all_months m
),
running_totals as (
select
product_id, date_expected, month_expected,
sum (qty) over (partition by product_id order by date_expected) as end_qty,
row_number() over (partition by product_id, month_expected
order by date_expected desc) as rn
from stock_calc
)
select
product_id, month_expected, end_qty
from running_totals
where
rn = 1
关于postgresql - SQL计算每月库存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34451601/
我是 PrestaShop 的新手。我遇到了一个问题,无法在 PrestaShop 从库存中减去商品的代码中找到。 当客户创建订单并选择付款时,商品将从库存中减去,但如果客户不付款并返回,则商品不会退
是否有最好的方法在关系数据库中存储诸如玩家背包之类的数据? 假设我想将玩家背包存储在数据库中。 表“eq”的数据库模型如下所示: 玩家 ID |槽 |商品编号 |金额 现在假设我在数据库中有这一行:
有没有一种方法可以在不使用 [all:vars] 的情况下在组之间继承变量 例子: [GROUP_A] server-A1 [GROUP_A:vars] vpc_cidr="192.10.0.0/21
我的 WooCommerce 插件遇到技术问题,但似乎无法找到答案。我得到了一个可变产品,有两个不同的研讨会时间。举一个简单的例子: 产品:事件当天门票 研讨会 1:红色 |蓝色|绿色 研讨会 2:红
我正在制作一个需要访问用户的 Steam 库存的网站。我找到了一个用于获取 Team Fortress 2 库存、Dota 2、CS:S、CS:GO 和 Portal 2 的 API。但我没有找到任何
我正在建立一个 woocommerce 网上商店。 这是一家手机壳网店,客户想在 woocommerce 后台保留库存,只有一个问题: 它们有不同的型号,例如 iPhone 4 和 iPhone 5。
我在 CodeBlocks (Windows 7) 中使用 GTK,并尝试创建 gtk_button_new_from_stock 所以我使用了以下代码: #include #include in
我有一个名为“条目”的表,我在其中保存每日销售和购买交易/条目。 “条目”表如下所示: ---条目表--- EntryDate EntryType Item Qty Rate
假设我有以下两条记录; tran_id item_id qty_in qty_out price 1 1 15
当我点击元素栏中的元素时,它什么都不做,我可以将它拖到任何我想要的地方。然后我重新打开库存,元素又回来了。我希望单击该项目(在本例中为通知项目)以切换通知 boolean 值并关闭库存。请帮忙。这可能
(我使用的是 Java,因此添加了“Java”标签,以防它影响任何答案,但有些人可能会认为该标签是不必要的。) 考虑以下因素: 我有一个阳台/阳台可以进行图形规划。作为最终计划的一部分,我需要列出 b
我有 2 个表 Tblinkreceiving 和 Tblinkdelivery。我想显示每个 inkcode 的库存余额。我尝试了下面的 sql 连接查询,但当我交叉检查手动计算时,许多 inkco
所以在很大程度上我明白我做错了什么,问题是我不知道如何解决它。 目标:这是一个必须包含可操作的菜单和库存管理功能的商店管理系统。为此,我使用数组来添加商店的商品、它们的描述和它们的数量。所有数组都部分
我发现设置 pg_hba.conf 文件非常困难。这是浪费我时间的常见情况。我需要做什么? 首先,在 Amazon、Digital Ocean 或我自己的硬件上安装新安装的 Linux 发行版的虚拟机
我正在尝试修改旨在与 HTML5 和 Javascript 一起使用的库存列表 Dynagrid 演示,它最初设计用于每次订阅订阅一个项目。 在我的例子中,我已将此演示连接到我的 lightstrea
元素以件和盒子的形式出现。 例如假设, 我购买了 100 片(片剂)medicineX。 我购买了一盒,其中包含50 medicineY。 现在元素仅按件分配。 意味着 MedicineX 将根据他们
我正在尝试使用 Terraform 中的 local_file 函数创建 Ansible 库存文件(我愿意接受以不同方式执行此操作的建议) 模块“vm”配置: resource "azurerm_li
我正在尝试使用 Terraform 中的 local_file 函数创建 Ansible 库存文件(我愿意接受以不同方式执行此操作的建议) 模块“vm”配置: resource "azurerm_li
我想知道是否有更有效/更干净的方法来执行以下操作。假设我有一个包含 2 列的数据框,百分比(基于之前的价格)和操作,玩/买 (1) 或不玩/卖 (-1)。它基本上与股票有关。 为简单起见,请考虑示例
不确定如何表达,但我正在创建一个音乐应用程序,并且我有一个流派选项卡按钮,该按钮将流派列为 UICollectionView 中的单元格。 然后用户选择一个流派,比如“Hip-Hop”,然后会显示相应
我是一名优秀的程序员,十分优秀!