[英]mysql : compare two row on same table
我有这样的输出:
+-----------+------------+--------------+
| client_id | date | spends |
+-----------+------------+--------------+
| 57 | 2014-09-28 | 39576.384391 |
| 57 | 2014-10-05 | 22664.382575 |
+-----------+------------+--------------+
我需要这样的行:如果前一周的支出为空,而本周有支出。
这是您需要的吗?
select t.*
from table t
where spend is not null and
exists (select 1
from table t2
where t2.client_id = t.client and
t2.spends is null and
t2.date = t.date - interval 7 days
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.