sql server关于分组查询,关联查询更新及导出脚本的几个点

今天遇到的几个点,很长时间没用了记录下

查询关联数据后更新

update 表a  set a.字段1 =b.字段1  ,a.字段2 =b.字段2   
from  表a  a  inner join 表b b  with(nolock) on  a.相关字段=b.相关字段 
where  isnull(a.字段1,'')<> ''  or  a.字段2 is not null 

详细可参考:https://www.cnblogs.com/baili-luoyun/p/11136698.html

查询各分组中一条记录

select b.* from 
(select a.*,row_number() over (partition by1 order by2 desc) rn 
from a) b 
where rn=1;

参考:https://blog.csdn.net/zhu_nana/article/details/51729013

导出脚本,含结构和数据

最主要的一步
在这里插入图片描述

详细可参考:https://jingyan.baidu.com/article/eae07827ad76ba1fed548573.html

猜你喜欢

转载自blog.csdn.net/s_156/article/details/113541469