更改SQL中重复列的值

时间:2015-03-13 23:56:30

标签: sql sqlite

我有下表: enter image description here

我想删除前三列中的重复值以包含下表: enter image description here

我该怎么做?我在这个网站上尝试了几种解决方案但没有成功。

1 个答案:

答案 0 :(得分:0)

您可以使用相关的子查询来模拟row_number,从那里可以使用case表达式。

select
  case when rn = 1 then title else '' end as title,
  case when rn = 1 then matter else '' end as matter
 -- ...
from (
  select *
    , (select count(*) from tbl as t2 
       where t2.title = t1.title
        and t2.date <= t1.date) as rn
  from tbl as t1
) as t