正在从数据库检索结果


Retrieving Result From Database

这是我的表结构:

Table Call_Log
id | StationId | LoginId |  keystroke | timestamp

我需要能够找到在按键"5"之后,在按键"Q"之间,按键"1"被按下了多少次。

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

此外,我需要以一种方式来做,这样我就可以向find列添加更多的键,它也可以找到它们。因此,如果我想在"5"answers"1"之后查找密钥3,它可以执行类似的操作。

Ex: 'Q','5','1','3','Q' will return true
but 'Q','5','1','2','Q' will return false
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'
;