2017-11-30 8 views
0

を使用して最後の非NULL値とNULL値を置き換えI持っているテーブルと呼ばれる量:赤方偏移

+----------+----------+ 
| date  | quantity | 
+----------+----------+ 
| 30/11/17 | 90  | 
+----------+----------+ 
| 01/12/17 |   | 
+----------+----------+ 
| 02/12/17 |   | 
+----------+----------+ 
| 03/12/17 | 1622  | 
+----------+----------+ 
| 04/12/17 |   | 
+----------+----------+ 
| 05/12/17 | 9092  | 
+----------+----------+ 
| 06/12/17 |   | 
+----------+----------+ 
| 07/12/17 |   | 
+----------+----------+ 
| 08/12/17 | 2132  | 
+----------+----------+ 
| 09/12/17 |   | 
+----------+----------+ 
| 10/12/17 | 2889  | 
+----------+----------+ 

そして私は、私は、以前の非ヌル値を持つ空白を埋めることができるように、それを選択します:私は赤方偏移1.0.1499、GCCのGCC(GCC)3.4.2 20041017(Red Hatの3.4.2-6.fc3)でコンパイルのi686-pc-linux-gnuのよう、上のPostgreSQL 8.0.2を使用しています

+----------+----------+ 
| date  | quantity | 
+----------+----------+ 
| 30/11/17 | 90  | 
+----------+----------+ 
| 01/12/17 | 90  | 
+----------+----------+ 
| 02/12/17 | 90  | 
+----------+----------+ 
| 03/12/17 | 1622  | 
+----------+----------+ 
| 04/12/17 | 1622  | 
+----------+----------+ 
| 05/12/17 | 9092  | 
+----------+----------+ 
| 06/12/17 | 9092  | 
+----------+----------+ 
| 07/12/17 | 9092  | 
+----------+----------+ 
| 08/12/17 | 2132  | 
+----------+----------+ 
| 09/12/17 | 2132  | 
+----------+----------+ 
| 10/12/17 | 2889  | 
+----------+----------+ 

これをどのように達成できますか?

ありがとうございます!

select date,(select t.quantity from [tablename] t where t.quantity is not null and t.date <= t1.date 
order by t.date desc limit 1) from [tablename] t1; 

t.quantity is not nulllast_value(quantity ignore nulls) over (order by date rows unbounded preceding)

よう

答えて

0

何かが、それはあなたがの行に何かを使用することができ、指定したウィンドウ

0

に最後の値を返す窓関数だそれは確認します結果セットにはnull値はありません。

t.date <= t1.date:最後の既知の値が選択されます。

関連する問題