Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改SQL中重复列的值_Sql_Sqlite - Fatal编程技术网

更改SQL中重复列的值

更改SQL中重复列的值,sql,sqlite,Sql,Sqlite,我有下表: 我希望删除前三列中的重复值,以获得下表: 我该怎么做?我在这个网站上尝试了几种解决方案,但没有成功。您可以使用相关子查询来模拟行数,从那里可以使用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(*)

我有下表:

我希望删除前三列中的重复值,以获得下表:


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

您可以使用相关子查询来模拟行数,从那里可以使用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

这最好在应用程序层而不是数据库中完成。结果表并不表示无序集,因为前三列没有值的行需要位于正确的位置。是的,我认为这是最佳选择