- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
情况是这样的:
我们有产品“A123”,我们必须记住它的最低价格。一种产品的价格来自随机数量的商店,无法判断商店 x 何时向我们发送“A123”的价格。
所以我有带列的 SQL 表:
product_number
price
shop (from which shop this price comes)
用于更新产品价格的 SQL 函数如下所示(这是 SQL 伪代码,语法无关紧要):
function update_product(in_shop, in_product_number, in_price)
select price, shop into productRow from products where product_number = in_product_number;
if found then
if (productRow.price > in_price) or (productRow.price < in_price and productRow.shop = in_shop) then
update row with new price and new shop
end if;
else
insert new product that we didn't have before
end if;
(productRow.price < in_price and productRow.shop = in_shop) 条件是为了防止出现这种情况:
在产品表中我们有
A123 22.5 amazon
然后又是来自亚马逊的信息:
A123 25 amazon
由于上述情况,我们将价格更新为更高的正确行为。
但算法在这种情况下失败了:我们在产品表中再次有一行:
A123 22.5 amazon
然后是来自 merlin 的信息
A123 23 merlin (we don't update because price is higher)
然后是来自亚马逊的信息
A123 35 amazon
然后我们更新表,现在我们有:
A123 35 amazon
但这是错误的,因为 merlin 早些时候对该产品的价格较低。
知道如何避免这种情况吗?
最佳答案
解决问题的唯一方法是跟踪每家商店的价格,然后只返回最低的当前价格。因此,例如,您需要一张与已有表格类似的表格,但是当您从表格中选择如下内容时:
select min(price)
from products
where product_number = :my_product
就我个人而言,我会保留您何时收到产品价格更新的时间戳,以便您能够确定何时收到更新。
关于sql - 最低价选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1920204/
我试图在折线图或面积图的工具提示中显示开盘价、最高价、最低价和收盘价。现在,折线图和面积图的数据正在 JSON 数组中发送,如下所示 {timestamp, close} 现在对于 OHLC 或烛台图
假设原始数据是: Timestamp High Low Volume 10:24.22345 100 99 10 10:24.23345 110 97 20 10:24
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭12 年前。 Improve th
类似于create an OHLC data from Date, time, price using C# ,如何将基本交易数据转换为 OHLC(或开盘价、最高价、最低价、收盘价)的理论并将其应用于
我有以下格式的连续数据流,我想根据定义的时间片(如 5 分钟、10 分钟、30 分钟等)将其转换为开盘价、最高价、最低价和收盘价。同时 buy_quantity sell_quantity 也应该根据
我正在尝试使用 Convert data to OHLC (Open, High, Low, Close) in JavaScript? 中的脚本将一些图表数据转换为 OHLC。唯一的问题是我的数据与
我是一名优秀的程序员,十分优秀!