0

次の行があると仮定します。

'employee' , 'is_here' , 'ts'
      1    ,    1      ,   22
      2    ,    1      ,   33
      1    ,    0      ,   44
      1    ,    0      ,   55
      2    ,    0      ,   66
      1    ,    0      ,   77
      2    ,    0      ,   88
      1    ,    1      ,   99

従業員が変更されたときにその結果を表示する方法はありis_hereますか?

たとえば、従業員 #1is_hereが変更された行を取得したいので、出力は次のようになります。

1,1,22 1,0,44 1,1,99

それは難しいと思います:)

4

1 に答える 1

1

一度に 1 人の従業員に対してのみクエリを実行する限り

set @state = -1;

select employee,
       @state := is_here as changed_to,
       ts
  from working
 where employee = 1 
   and (@state = -1 or @state != is_here);

http://sqlfiddle.com/#!2/a71d8/11

于 2012-10-18T20:57:59.607 に答える