我使用的是oracle sql,表中有重复的行,如下所示:
Month Product
March ENVOY & External Keyboard (22)
March ENVOY & External Keyboard (22)
March ENVOY & External Keyboard (22)
March ENVOY & External Keyboard (22)
March ENVOY & External Keyboard (22)
March ENVOY & External Keyboard (22)
April ENVOY & External Keyboard (22)
April ENVOY & External Keyboard (22)
April ENVOY & External Keyboard (22)
April ENVOY & External Keyboard (22)
April ENVOY & External Keyboard (22)
我需要把它变成这样:
Month Product
March ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
April ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
ENVOY & External Keyboard (22)
我想用 SELECT (case when row_number() over (partition by times.calendar_month_name order by (select NULL)) = 1 then times.calendar_month_name end) Month
但不起作用。。。有什么想法吗?
3条答案
按热度按时间dl5txlt91#
你可以用
LAG()
窗口功能:请看演示。
结果:
yduiuuwa2#
小菜一碟sql*plus:
dohp0rv53#
这种类型的操作最好在应用程序级别完成。你可以用
row_number()
,但您需要小心:请注意,sql查询以不确定的顺序返回结果。所以你需要一个外罩
order by
以保证排序(即“第一”行具有值)。因为您要处理的是完全重复的,所以没有唯一的排序键,所以即使对row_number()
可能产生不同的结果——因此使用子查询。