-1
我有以下數據如何
sk_patient casenumber src status pen_dt
-1 2345 POPDB CLOSED 2012-01-01
-1 235 POPDB CLOSED 2012-01-01
-1 245 JCARE CLOSED 2012-01-02
1244 2 POPDB CLOSED 2012-01-01
273 2345 POPDB CLOSED 2012-03-04
1244 23 JCARE CLOSED 2012-05-02
需要被轉換爲以下不同src
列值的基礎上,SRC柱的不同的價值轉移到不同的列。
sk_patient casenumber1 src1 status1 pen_dt1 casenumber2 src2 status2 pen_dt2
-1 2345 POPDB CLOSED 2012-01-01 245 JCARE CLOSED 2012-01-02
-1 235 POPDB CLOSED 2012-01-01 NULL NULL NULL NULL
1244 2 POPDB CLOSED 2012-01-01 23 JCARE CLOSED 2012-05-02
273 2345 POPDB CLOSED 2012-03-04 NULL NULL NULL NULL
例如,
爲-1
我們有3行,但他們兩個人有相同的src
,因此我們將它們,因爲它是,但3行有不同的值。因此,需要將其移至src2
列以及相關的列值。
將會有最小1和最大3個不同的src
可以關聯任何特定的sk_patient
。
===更新===
直到現在,我能夠做到以下
seq sk_patient casenumber src status pen_dt
2 -1 2345 POPDB CLOSED 2012-01-01
2 -1 235 POPDB CLOSED 2012-01-01
1 -1 245 JCARE CLOSED 2012-01-02
2 1244 2 POPDB CLOSED 2012-01-01
1 273 2345 POPDB CLOSED 2012-03-04
1 1244 23 JCARE CLOSED 2012-05-02
我用下面的查詢
select dense_rank()
over(partition by sk_patient order by sk_patient, src) as seq,
* from patient
誰能幫我像上面的例子那樣移動值?
有沒有標識列?我們如何訂購數據? – Wanderer
@Wanderer不需要訂購。但是,解決方法,我們可以使用'src'列來訂購? – unnamed
@Matt如果'src'列是相同的,則爲相同的'sk_patient'按順序遍歷現有行,否則將不執行任何操作,否則移動到2nd,如果發現不同,則移動到第3個。 – unnamed