0

と制御値idを持つテーブルがあります。timestamp

制御値が 0 である ID が 4 日以上連続してクエリを実行する必要があります

TimeS   ID  Kontrol
2012-06-18  5457554F-E9A5-4312-8BA3-424B2333D0B7    1
2012-06-14  3FC4AC80-7D94-496A-92D0-22350CA3CEA9    1
2012-06-14  FE3C1872-0F13-48CC-A6C9-BBE0EAB07B9D    0
2012-06-13  FE3C1872-0F13-48CC-A6C9-BBE0EAB07B9D    0
2012-06-12  FE3C1872-0F13-48CC-A6C9-BBE0EAB07B9D    0
2012-06-11  FE3C1872-0F13-48CC-A6C9-BBE0EAB07B9D    0

FE3C1872-0F13-48CC-A6C9-BBE0EAB07B9たとえば、返されるはずです。

4

3 に答える 3

0

これを試して:

SELECT t1.id
  FROM tableName t1
 WHERE t1.kontrol = 0
   AND EXISTS (SELECT 1
                 FROM tableName t2
                WHERE t2.id = t1.id
                  AND t2.kontrol = 0
                  AND t2.timeS = t1.timeS + 1
                  AND EXISTS (SELECT 1
                                 FROM tableName t3
                                WHERE t3.id = t2.id
                                  AND t3.kontrol = 0
                                  AND t3.timeS = t2.timeS + 1
                                  AND EXISTS (SELECT 1
                                                FROM tableName t4
                                               WHERE t4.id = t3.id
                                                 AND t4.kontrol = 0
                                                 AND t4.timeS = t3.timeS + 1)))
于 2013-03-26T10:22:20.667 に答える
0
SELECT DISTINCT t1.id
FROM table t1
     INNER JOIN 
     table t2 ON t2.TimeS+1 days=t1.TimeS
     INNER JOIN 
     table t3 ON t3.TimeS+2 days=t1.TimeS
     INNER JOIN 
     table t4 ON t4.TimeS+3 days=t1.TimeS
WHERE t1.Control = 0 AND
      t2.Control = 0 AND
      t3.Control = 0 AND
      t4.Control = 0
于 2013-03-26T10:23:07.230 に答える
0

このクエリを試してください

select 
  id, 
  count(distinct TimeS) 
from 
  table1
where 
  kontrol=0
group by 
  id 
having 
  count(distinct TimeS) >= 4;

フィドル

于 2013-03-26T10:31:30.390 に答える