我输出如:
+-----------+------------+--------------+
| client_id | date | spends |
+-----------+------------+--------------+
| 57 | 2014-09-28 | 39576.384391 |
| 57 | 2014-10-05 | 22664.382575 |
+-----------+------------+--------------+
我需要这样的行,如果前一周的花费是空的,那么当前的一周花费了。
答案 0 :(得分:1)
这是你需要的吗?
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
);