- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 SQL 表 https://pasteboard.co/IfFt5rF.png其中有数千条关于产品流的记录,如果产品被出售,数量为负,当产品被购买时,数量为正。 product_id
是每个产品的唯一标识符。我想输入日期并找出该日期之间的每个月,当时库存为零。
我想首先通过找出过去期间的总和来计算每个月的起始余额,然后逐行添加新数据,如果它为零,那么它是一个日期,但这种逻辑看起来非常糟糕,甚至不知道如何在 SQL 中处理它。
我使用 Microsoft SQL 2014
declare @Table table (general_id bigint, date datetime, product_id bigint, quantity float,
price float, code nvarchar(max), name nvarchar(max), partnumber nvarchar(max),
description nvarchar(max), rate float, comment nvarchar(max), currency nvarchar(max), waybill nvarchar(max))
insert into @Table (general_id, date, product_id, quantity, price, code, name, partnumber, description, rate, comment, currency, waybill)
select 1, '2019-03-1 16:33:00', 1, 10, 100, 101010, 'test', 'testnumber', 'testdescription', 1.0, 'testcomment', 'USD', 'nobill'
union all
select 2, '2019-03-2 16:33:09', 1, -5, 100, 101010, 'test', 'testnumber', 'testdescription', 1.0, 'testcomment', 'USD', 'nobill'
union all
select 3, '2019-03-3 16:33:12', 1, -3, 100, 101010, 'test', 'testnumber', 'testdescription', 1.0, 'testcomment', 'USD', 'nobill'
union all
select 4, '2019-03-4 16:39:00', 1, -2, 100, 101010, 'test', 'testnumber', 'testdescription', 1.0, 'testcomment', 'USD', 'nobill'
union all
select 5, '2019-03-4 16:39:41', 2, 40, 100, 102020, 'test', 'testnumber', 'testdescription', 1.0, 'testcomment', 'USD', 'nobill'
union all
select 6, '2019-03-5 16:39:00', 2, -40, 100, 202020, 'test', 'testnumber', 'testdescription', 1.0, 'testcomment', 'USD', 'nobill'
union all
select 7, '2019-03-6 16:39:00', 1, 25, 100, 101010, 'test', 'testnumber', 'testdescription', 1.0, 'testcomment', 'USD', 'nobill'
SELECT DISTINCT product_id, code, name, partnumber, SUM(quantity)
FROM @TABLE
GROUP BY product_id, code, name, partnumber
ORDER BY product_id ASC
如果输入的日期范围为 2019-03-01 到 2019-03-31,则当前案例的输出将为。产品编号:1缺货日期:2019-03-4zero_stock_days:2 因为在 2019-03-6 购买了商品并且已经有货
产品编号:2缺货日期:2019-03-5zero_stock_days:26 因为它再也没有买过
最佳答案
使用 Sql Server >2008 中可用的窗口函数尝试此查询 :)
SELECT [lagDate] outOfStockStart,
[date] outOfStockEnd,
product_id,
daysOutOfStock
FROM (
SELECT *,
CASE WHEN LAG(stock) OVER (PARTITION BY product_id ORDER BY [date]) = 0 AND stock > 0 THEN
DATEDIFF(day, lagDate, [date]) ELSE NULL END daysOutOfStock
FROM (
SELECT [date],
LAG([date]) OVER (PARTITION BY product_id ORDER BY [date]) lagDate,
product_id,
SUM(quantity) over (PARTITION BY product_id ORDER BY [date]) stock
FROM @TABLE
) a
) a WHERE daysOutOfStock IS NOT NULL
关于sql-server - 从库存表中,找出库存为零的两个日期之间的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56230854/
我是 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”,然后会显示相应
我是一名优秀的程序员,十分优秀!