2016-04-26 7 views
0

Netezzaのweb_eventテーブルに次の形式でデータがあります。Netezza SQLから逐次レコードの値を収集する

**vstr_id | sessn_id | event_ts | wbpg_nm** 
*V1  | V1S1  | 02-02-2015 09:30:00 | /home/contacts* 
*V1  | V1S1  | 02-02-2015 09:20:00 | /home/login* 
*V1  | V1S1  | 02-02-2015 09:50:00 | /home/search* 
*V2  | V2S1  | 02-02-2015 09:10:00 | /home* 
*V2  | V2S2  | 02-02-2015 09:20:00 | /home/news* 

これはソーステーブルです。

私はそのweb_eventテーブルを使用して、次のような別のテーブルを作成しようとしています。

私はpage_pathテーブルは以下のようにロードすることにしたい

Insert into page_path (select VSTR_ID, 
      SESSN_ID, 
      EVENT_ts, 
      *?* as PREV_WBPG_NM, 
      WBPG_NM, 
      *?* as NXT_WBPG_NM, 
      from web_event) 

を行うにしようとしています。

この下の表では、event_ts列のソート順に基づいて、前のページ列と次のページ列のデータをロードします。

これをNetezzaまたは任意のSQLクエリでどのように行うことができますか?

**vstr_id | sessn_id | event_ts | previous_wbpg_nm | wbpg_nm | next_wbpg_nm** 
*V1  | V1S1  | 02-02-2015 09:30:00 | /home/login | /home/contacts | /home/search* 
*V1  | V1S1  | 02-02-2015 09:20:00 | null | /home/login | /home/contacts* 
*V1  | V1S1  | 02-02-2015 09:50:00 | /home/contacts | /home/search | null * 
*V2  | V2S1  | 02-02-2015 09:10:00 | null | /home/ | null* 
*V2  | V2S2  | 02-02-2015 09:20:00 | null | /home/news | null* 

答えて

2

あなただけlag()lead()を使用して、SQLクエリでこれを行うことができます。

select vstr_id, sessn_id, event_ts, 
     lag(wbpg_nm) over (partition by vstr_id, sessn_id order by event_ts) as prev_wbpg_nm, 
     wbpg_nm, 
     lead(wbpg_nm) over (partition by vstr_id, sessn_id order by event_ts) as next_wbpg_nm 
from page_path; 
+0

あなたの助けをありがとうございました! – RAJESH

+0

こんにちはゴードン、これについての任意のアイデアhttp://stackoverflow.com/questions/36898926/session-duration-and-time-on-page-calculation-using-sql – RAJESH

関連する問題