sql-server – 使用select distinct插入
发布时间:2020-12-12 07:29:45 所属栏目:MsSql教程 来源:网络整理
导读:比方说,我有2个表t1和t2. create table t1 {id int not null,col1 int null,col2 int null,col3 int null}create table t2{id uniqueidentifier not null,col3 int null} 我想将下面的结果集插入表t2. select distinct col1,col2,col3 from t1 如何使用查询实
比方说,我有2个表t1和t2.
create table t1 { id int not null,col1 int null,col2 int null,col3 int null } create table t2 { id uniqueidentifier not null,col3 int null } 我想将下面的结果集插入表t2. select distinct col1,col2,col3 from t1 如何使用查询实现此目的?我试过下面的声明,但我知道它在语法上是错误的. insert into t2 select newid(),distinct col1,col3 from t1 解决方法insert into t2 select newid(),a.* from (Select distinct col1,col3 from t1) a (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读