简体   繁体   English

如何在MySQL上搜索?

[英]How can I search this on MySQL?

Every day the cron insert on data_log.table the logs of all coins. Cron每天都会在data_log.table上插入所有硬币的日志。

I use the API from coinmarketcap. 我使用来自coinmarketcap的API。

API Documentation: https://coinmarketcap.com/api API文档: https : //coinmarketcap.com/api

I have a lot of duplicates with the Cryptocurrency names. 我有很多重复的加密货币名称。

The challenge is to search between 2018-02-11 and 2018-02-18 to find a coin in this period triple who your market cap or your volume. 面临的挑战是,在2018年2月11日至2018年2月18日之间进行搜索,以找到此时期内市值或交易量三倍的代币。

I want to search all the coins with one expression on mySQL. 我想用mySQL上的一个表达式搜索所有硬币。

My API Consult: http://127.0.0.1/db.php?json=data_log&startdate=2018-02-12&finaldate=2018-02-17 我的API咨询: http : //127.0.0.1/db.php?json=data_log&startdate=2018-02-12&finaldate=2018-02-17

How can I do this? 我怎样才能做到这一点?

I don't want to search one specific coin, I want to search all coins in this period got a triple of your value. 我不想搜索一个特定的硬币,我想搜索此期间的所有硬币,它们的价值是您的三倍。

This is the structure: 结构如下:

 `data_log`(`id`, `moeda`, `moeda_simbolo`, `market_cap`, `volume`, 
            `data_cadastro`, `percent_change_1h`, `percent_change_24h`, 
            `percent_change_7d`, `price_usd`) 
  VALUES   (1, 'Bitcoin', 'BTC', '134001640106', '6628000000.0', 
            '2018-02-11', '-1.07', '-10.47', 
            '-11.75', '7948.84')

Example of storage: 存储示例:

(1313, 'Kubera Coin', 'KBR', '1807270.0', '155830.0', '2018-02-11', '-2.27', '-16.9', '-7.76', '0.0157946'),
(1314, 'Renos', 'RNS', '1788409.0', '2235.62', '2018-02-11', '2.0', '-3.49', '-4.48', '0.0536157'),
(1315, 'FujiCoin', 'FJC', '1786980.0', '2300.57', '2018-02-11', '4.67', '-2.84', '-23.1', '0.00137009'),
(1316, 'Bankcoin', 'B@', '1780694.0', '2679.29', '2018-02-11', '3.32', '348.87', '72.86', '0.173021'),
  1. You have dates in the log without an hour. 您在日志中的日期没有一个小时。 If you want to increase the detail, then you will have a problem. 如果您想增加细节,那么您将遇到问题。

  2. To achieve what you want, you must sum up the values from the given date range and compare them to the values from the beginning of the period. 要实现所需的功能,必须对给定日期范围内的值求和,并将其与期间开始时的值进行比较。

     SELECT * FROM (SELECT moeda, sum(market_cap) as sum_cap, sum(volume) AS sum_volume FROM data_log WHERE data_cadastro >= '2018-02-11' AND data_cadastro <= '2018-02-18' GROUP BY moeda) AS sum_log LEFT JOIN (SELECT * FROM data_log WHERE data_cadastro = '2018-02-11') AS dl ON dl.moeda = sum_log.moeda WHERE (sum_cap - market_cap) / 3 > market_cap OR (sum_volume - volume) / 3 > volume; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM