用row_number() over(partition by key1 order by key1 )可以显示组内序号,我还想显示组序号,怎么搞
field key1 key2 value
data k1 k11 v11
k1 k13 v12
k1 k13 v13
k2 k21 v21
k2 k22 v22
我想显示 group groupin value
1 1 v11
1 2 v12
1 3 v13
2 1 v21
2 2 v22
------解决方案--------------------SELECT dense_rank() over(PARTITION BY KEY1 ORDER BY key1) AS
GROUP , row_number() over(PARTITION BY key1
ORDER BY key1) AS groupin, VALUE
FROM t
这样子试一下。
用dense_rank()这个分析函数来实现。
------解决方案--------------------select dense_rank() over(PARTITION BY KEY1 ORDER BY key1) "group ",
row_number() over(partition by key1 ORDER BY key1) groupin, "VALUE "
from table1;