sql 数据库查询语句总结

1,将表中的某一列(CostTime)中的post days 全部替换成Tage

update SYS_Delivery set CostTime = REPLACE(CostTime,'post days','Tage' )

 

 

2.将有一个表的数据更新相对应的字段。

 

 

select * from SYS_ProtectionVal

Select * from SYS_ProtectionVal$

 

 

update SYS_ProtectionVal set ProtectionVal = SYS_ProtectionVal$.ProtectionVal 

from SYS_ProtectionVal$ 

Where SYS_ProtectionVal.DID = SYS_ProtectionVal$.DID

 

使用excel将数据导入到数据库中。

 

3.创一个表中的数据复制到新创建的另外一个表中去。

 select * into NewTable from OldTable 

 

应用:当做临时表来使用

 

 

 

4实现数据的二次查询(可用临时表来替换)

 select * from (select * from tableNew) as b where "条件"

 

 

5.跨数据库中的访问,将一个数据库中的某一个表的数据存放到另外一张表。

 

insert into tableneed(name) select name from [数据库名].[dbo].[tablegive]

 

6.说明:两张关联表,删除主表中已经在副表中没有的信息

delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

 应用:可以将没有下过单的用户的信息删除掉。在数据库中只保留有下过单账号。

 

 

 

7.将一个星期前的数据显示出来

 

   select * from table where datediff(D,startTime,getdate)>7 


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值