惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - qy

枚举 Duwamish7资料收集- [] 学习Duwamish7的MSDN说明及相关技术策略 Duwamish7学习笔记(七) Duwamish7学习笔记(六) Duwamish7学习笔记(五) Duwamish7学习笔记(四) Duwamish7学习笔记(三) Duwamish7学习笔记(二) Duwamish7学习笔记(-) jQuery介绍及语法----转载 浅谈.net事件机制 使用EditPlus2编写C#代码 跟踪用户会话 按钮确认(js与C#交互) Visual Studio 2003/Visual Studio 2005常用快捷键 ----转 最优化javascript自定义对象 BOM 关于用div实现table的效果
3-28学会的几句sql语句
qy · 2007-03-28 · via 博客园 - qy
   

   1.两张结构相同的表,使他们的数据同步
      
      create table #A(id int, y vachar(10))
      create table #B(id int, y varchar(10))
      
      insert into #A 
         select 1, 'a1'
         union
         select 2, 'a2'
      select * from #A
      
      insert into #B
         select 1, 'b1'
         union
         select 2, 'b2'
      select * from #B

      update #B set y=#A.y from #B,#A where #A.id=#B.id
      
      select * from #B
      
      drop table #A
      drop table #B

   2.对于一张表的一列,查找出不重复的记录

      create table #A(x int,y varchar(10))
      
      insert into #A 
         select 1, '张三'
         union  
         select 2, '张三'
         union
         select 3, '李四'

      select distinct y,count(y) [count] from #A group by y

      drop table #A

   3.将表A查询成下面的样子
表A

id    x
1    abc
2    xyz
3    abc
4    abc

B
abc  xyz
3     1  

   select * into #temp from( select
      1 id,    'abc' x
      union
      select 2,    'xyz'
       union
      select 3,    'abc'
      union
      select 4,    'abc'
      ) A

     select * from #temp
    declare @sql varchar(8000)
      set @sql = 'select '

    select @sql = @sql + ltrim(str(f2)) + ' ' + f1 + ', ' from 
   (
       select x f1, count(*) f2 from #temp group by x
    ) A


     set @sql =  substring(@sql, 1, len(@sql) - 1)

   select @sql

   exec( @sql )