我从我的表中进行了简单的选择,其中id_usu_detalle=80
:
登录:
如何使用连续的log_estado 0, 1, 0, 1
进行选择,如下所示:
log_id | id_usu_detalle | log_estado | log_horafecha
1775 | 80 | 0 | 2014-07-08 15:20:51
1774 | 80 | 1 | 2014-07-08 15:20:31
1513 | 80 | 0 | 2014-07-04 10:19:34
1512 | 80 | 1 | 2014-07-04 10:18:53
1483 | 80 | 0 | 2014-07-03 18:37:45
1482 | 80 | 1 | 2014-07-03 18:36:16
有可能吗?
答案 0 :(得分:2)
SELECT
log_id, id_usu_detalle, log_horafecha, log_estado
FROM
(SELECT
log_id,
id_usu_detalle,
log_horafecha,
log_estado,
IF(@A = log_estado, 5, 0) AS counter,
@A:=log_estado
FROM log
CROSS JOIN (SELECT @A:=10000) AS t) AS temp
WHERE counter = 0;