【问题标题】:Retrieving Result From Database从数据库中检索结果
【发布时间】:2012-01-25 19:43:14
【问题描述】:

这是我的表结构:

Table Call_Log

id | StationId | LoginId |  keystroke | timestamp

我需要能够找出在按键“Q”之间的按键“5”之后按键“1”被按下了多少次。

EX: 'Q','5','1','Q' will return true
but 'Q','5','2','Q' will return false

另外,我需要以某种方式向查找列添加更多键并且它也可以找到它们。因此,如果我想在 '5' 和 '1' 之后查找密钥 3,它可以做类似的事情。

Ex: 'Q','5','1','3','Q' will return true
but 'Q','5','1','2','Q' will return false

【问题讨论】:

  • 请告诉我,您没有在 mysql 数据库中记录每一次击键。
  • 您可以对搜索设置时间限制吗?如果您可以对搜索设置时间限制,那么使用 FSA 很容易实现。因为这只是一个 FSA 问题。
  • 你能贴出你试过的代码吗?
  • 我们怎么知道这些按键的编码?!我建议获取每次击键产生的控制代码并存储击键表示的数字的位掩码。这是确保安全的唯一方法。
  • 等等,我知道了!有一个包含两列的bit_lookup 表:bit_id(主键)和bit(分别具有数据类型smallint 和bit(1))。然后你可以有一个keystroke_lookup 表,其中包含keystroke_id(主键)、bit_id(外键指bit_lookup)和bit_rank(这样我们就可以确定特定击键的位顺序)。我们还可以有一个keystroke_name 表,其中包含keystroke_id(与keystroke_lookup 表对应的外键)和keystroke(数据类型为char(1))列。那么其他所有表都可以参考keystroke_id。

标签: php sql regex


【解决方案1】:
SELECT count(*) FROM (
  SELECT
    IF(
      @matchstring='Q' AND keystroke='5', 
      @matchsting:='Q5',
      IF(
        @matchstring='Q5' AND keystroke='1',
        @matchstring:='Q51',
        IF (@matchstring='Q51' AND keystroke='Q',
          @matchstring:='Q51Q',
          @matchstring:=keystroke
        )
      )
    ) AS matchpart
  FROM
    (SELECT @matchstring:=''),
    Call_Log
  WHERE
    -- Your criteria here, might be "StationID=blah"
  ORDER BY
    Call_Log.`timestamp`
) AS baseview
WHERE matchpart='Q51Q'
;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 2014-06-17
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多