我有一个用户表,其中包含用户数据
++ id | username | btc_recive_address++
----------------------------------------
++ 1 | myuser | 123kahpoiq31328 ++
订单表
++ order_id | user_id | amount | order_timestamp
------------------------------------------------------
++ h6765-a1s | 1 | 0.1 BTC | 2014-04-09 13:21:34
------------------------------------------------------
++ kzg765-a1 | 1 | 0.1 BTC | 2014-04-09 17:11:23
和从比特币API检索数据的收集器表(这里我用btc_recive_address识别发件人)
++ block_chain | user | amount | timestamp
--------------------------------------------------------------------------------
++ 2d37e5351196... | 1 | 0.1 | 2014-04-09 16:21:34
--------------------------------------------------------------------------------
++ 123kjhg7231k.. | 1 | 0.1 | 2014-04-08 19:33:56
--------------------------------------------------------------------------------
我尝试将事务分配给order_id,例如从订单和收集器表生成联合视图,但是当数量和用户相同时我遇到问题
问题
用户放置多个具有相同值的订单
0,1 X 3
我从API获取交易数据,而不是使用reciver地址识别用户
someaddress - (此处交易有3个传入确认)
比我尝试构建MySQL视图作为比较
订单表与收集表如加入用户和金额。当金额和用户相同时,我没有从我的视图中的order_table获得唯一的transaction_id
这是视图查询
ALTER ALGORITHM=UNDEFINED DEFINER=`my_view`@`%` SQL SECURITY DEFINER VIEW `ci_orders_in` AS (
SELECT
`c`.`block_chain` AS `block_chain`,
`c`.`assigned_user` AS `assigned_user`,
`c`.`incoming_amount` AS `incoming_amount`,
`c`.`timestamp` AS `timestamp`,
`c`.`type` AS `type`,
`c`.`category` AS `category`,
`c`.`import_timestamp` AS `import_timestamp`,
`o`.`transaction_id` AS `transaction_id`,
`o`.`datum` AS `datum`,
`o`.`status` AS `status`,
`o`.`convert_coin` AS `convert_coin`,
`o`.`convert_coin_to` AS `convert_coin_to`,
`o`.`amount` AS `amount`,
`o`.`converted_amount` AS `converted_amount`,
`o`.`conversion_rate` AS `conversion_rate`,
`o`.`user` AS `user`,
`o`.`units_to_transfer` AS `units_to_transfer`,
`o`.`provision` AS `provision`
FROM (`ci_orders` `o`
JOIN `ci_collector` `c`
ON ((`o`.`user` = `c`.`assigned_user`)))
WHERE (`o`.`convert_coin` = `c`.`type`)
GROUP BY `o`.`converted_amount`)$$
DELIMITER ;
在这里,我应该使用另一个连接,它应该给我最近的时间戳,但我没有得到它
答案 0 :(得分:0)
只是看看你的观点,显而易见的是你没有向我们展示这些表格中的所有列,并且你已经捏造了这些表名,因为查询中有一列" user&#34 ;在ci_order表中,但在示例数据中有列" user_id"。但是,由于我在比特币SE网站上阅读了您的问题,而且我对您尝试做的事情模糊不清,我猜测您是否会想要一个类似于此的查询
[查询不正确]
修改强> 很抱歉没有仔细查看时间戳。这次我真的很想把你的数据集加载到SQL(MS SQL 2014)中,虽然我可能稍微重命名了这些列。这个怎么样?此外,如果您可以提供有关延迟的详细信息,那么它会有用,例如订单时间戳是否总是在收集器时间戳之后?
select *
from ci_orders
join ci_collector
on ci_orders.user_id = ci_collector.user_id
and ci_orders.amount = ci_collector.amount
and ci_collector.timestamp = (
select top 1 timestamp
from ci_collector
where ci_orders.user_id = ci_collector.user_id
and ci_orders.amount = ci_collector.amount
and ci_orders.timestamp > ci_collector.timestamp
order by timestamp desc
)