SQL的六个应用场景

场景一:SQL 将表A的数据拷贝到表B
select * into 表B from 表A

场景二:表A用于存储软件版本,同一个软件会有多个软件版本,获取最新的版本
select * from 表A where (id in (select max(id) as sid from 表A as ts  group by 软件名称,统一编号))

场景三 将字符串转换为数字排序
select * from 表A order by cast(字段A AS int)

场景四:SQL截取某一字段前的数字或是字符
select *,substring(设备代号,1,charindex('S',设备代号)-1)as num from 表A

场景五:SQL两列拷贝
update 表A set 列A=列B

场景六:判断数据库中的重复项
select  申请单号 from 表A where (申请单号 in(select 申请单号 from 表A as t group by申请单号 having (count(1)>=2))) 

你可能感兴趣的:(sql,数据库)