这是我用 mysql 查询 http://sqlfiddle.com/#!2/f2794/4制作的 sqlfiddle
当存在 = 0 时,它连续计算 10 天,但我需要添加第二个条件来计算存在 > 10 的情况。
例如
11 22 0 0 0 0 0 0 0 0 0 0 0 0 1
应该数 14
这是那个查询
select sum(count) total from (
SELECT COUNT(present) as count FROM (
SELECT
IF((q.present != 0), @rownum:=@rownum+1, @rownum:=@rownum) AS rownumber, @prevDate:=q.date, q.*
FROM (
SELECT
name
, date
, present
FROM
teacher, (SELECT @rownum:=0, @prevDate:='') vars
WHERE date BETWEEN '2013-07-01' AND '2013-07-31'
ORDER BY date, present
) q
) sq
GROUP BY present, rownumber
HAVING COUNT(*) >= 10
) d
所以,如果你能帮助我,请这样做:)
最好的问候米。