MySQL通过计算结果获取数据

时间:2016-06-03 09:45:00

标签: php mysql caching

我有一个包含10000行和2列INTegers($duration_time = time() - $start_timestamp; $actual_qty = $duration_time * $speed_qty_per_second; )的表。

当MySQL SELECT时,我需要从所选值计算结果。 我做计算:

WHERE $actual_qty > 100

我需要从表// will store list of rules var rules = [] // at least one capital letter rule rules.one_capital_letter = { fail_message: 'password needs at least one capital letter', validate: function(password){ return /[A-Z]/.test(password) } } // at least six letters rule rules.at_least_six_letters = { fail_message: 'password needs to have at least 6 characters', validate: function(password){ return password.length >= 6 } } function validate_password(password) { // goes through all the rules for(rule in rules) { if(!rules[rule].validate(password)) { return {success: false, message: rules[rule].fail_message} } } // return success after all rules are checked return {success: true, message: 'password validated successfully'} } // Test if it works var test_strings = ['abcd', 'Abcd', 'Abcdef'] for(i in test_strings) { $('body').append(test_strings[i] + ': ' + validate_password(test_strings[i]).message + '<br>') } 中选择数据。 很多用户经常会访问这些数据,例如每个用户每秒一次。

存储缓存数据的最佳方法是什么?

  • MEMORY MySQL表?
  • 文件(csv,XML)?

1 个答案:

答案 0 :(得分:0)

我认为sql解决方案可能很有用

 select 
   id,
   start_timestamp,
   speed_qty_per_second, 
   timediff(now(),start_timestamp)),
   timediff(now(),start_timestamp))* peed_qty_per_second
 from your_table