2014-10-07 56 views
0

比較兩個行我有喜歡的輸出爲:mysql的:在同一個表

+-----------+------------+--------------+ 
| client_id | date  | spends  | 
+-----------+------------+--------------+ 
|  57 | 2014-09-28 | 39576.384391 | 
|  57 | 2014-10-05 | 22664.382575 | 
+-----------+------------+--------------+ 

,我需要這樣的行,如果前一週花費爲null,並且當前有一週的時間。

+2

不清楚,請添加更多解釋 – 2014-10-07 11:56:29

+0

您可以添加一些示例數據,包括您正在談論的空值以及示例結果嗎? – 2014-10-07 11:56:35

回答

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 
      );