--方法(一):分组排练进行更新
----------------------------------------------------------------------------------------------------------------
create table a(id int identity,aid varchar(),name varchar())
insert into a select , 'a '
insert into a select , 'a '
insert into a select , 'a '
insert into a select , 'b '
insert into a select , 'b '
insert into a select , 'c '
insert into a select , 'a '
insert into a select , 'a ' create table b(id int identity,aid varchar(),name varchar())
insert into b select , 'a '
insert into b select , 'a '
insert into b select , 'b '
insert into b select , 'b '
insert into b select , 'b '
insert into b select , 'd ' select px=(select count() from a where aid = t.aid and name= t.name and id<t.id)+,* into #tb1 from a t
select px=(select count () from b where aid = t.aid and name= t.name and id<t.id)+,* into #tb2 from b t select * from #tb1
select * from #tb2
delete a where id in
(select id from #tb1 a where not exists(select * from #tb2 b where b.px=a.px and b.aid=a.aid and b.name=a.name)
and a.aid=)
insert into a
select aid,name from #tb2 a where not exists(select * from #tb1 b where b.px=a.px and b.aid=a.aid and b.name=a.name) -------------------------------------------------------------------------------------------------------------------
--方法(二):分组排练进行更新 create table tb1(ID int,Account int)
insert into tb1 values(, )
insert into tb1 values(, )
insert into tb1 values(, )
insert into tb1 values(, )
insert into tb1 values(, )
insert into tb1 values(, )
insert into tb1 values(, )
insert into tb1 values(, ) create table tb2(ID int,Account int)
insert into tb2 values(, )
insert into tb2 values(, )
insert into tb2 values(, )
insert into tb2 values(, )
insert into tb2 values(, )
insert into tb2 values(, )
insert into tb2 values(, )
insert into tb2 values(, ) select px=identity(int, ,),* into #t1 from tb1 order by account,id
select px=identity(int ,,),* into #t2 from tb2 order by account,id select a.id,a.account from #t1 a where not exists(select * from #t2 b where a.px=b.px and a.account=b.account)
-----------------------------------------------------------------------------------------------------------------
--删除临时表 drop table tb1,tb2,#t1,#t2

[SQL]分组排练进行更新的更多相关文章

  1. 取SQL分组中的某几行数据

    取SQL分组中的某几行数据 对表中数据分组,有时只需要某列的聚合值:有时却需要返回整行数据,常用的方法有:子查询.ROW_NUMBER.APPLY,总体感觉还是ROW_NUMBER比较直观.测试数据: ...

  2. sql 分组后显示每组的前几条记录

    sql 分组后显示每组的前几条记录 如   表中记录是             code       serialno             A1               1           ...

  3. SQL分组查询及聚集函数的使用

    今天要做一个查询统计功能,一开始有点犯难,上午尝试大半天才写出统计sql语句,才发现自己sql分组查询及聚集函数没学好:其实就是group by子句和几个聚集函数,熟练使用统计功能很简单.在此总结下今 ...

  4. SQL批量添加,更新,删除

    SQL语句: 存储过程: 代码: 这里说的是关于SQL的批量操作数据. 需要准备: 三层框架:利用 动软代码生成器(可以快速生成增删改查) 生成三层 Model,BLL,Dal ①DbHelpeSQL ...

  5. SQL中使用UPDATE更新数据时一定要记得WHERE子句

    我们在使用 SQL 中的 UPDATE 更新数据时,一般都不会更新表中的左右数据,所以我们更新的数据的 SQL 语句中会带有 WHERE 子句,如果没有WHERE子句,就回更新表中所有的数据,在 my ...

  6. 数据库:sql 多表联合更新【转】

    SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...

  7. Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例

    如何用一条sql语句实现批量更新?mysql并没有提供直接的方法来实现批量更新,但是可以用点小技巧来实现. 复制代码 代码如下: UPDATE mytable SET myfield = CASE i ...

  8. sql 分组后按时间降序排列再取出每组的第一条记录

    原文:sql 分组后按时间降序排列再取出每组的第一条记录 竞价记录表: Aid 为竞拍车辆ID,uid为参与竞价人员ID,BidTime为参与竞拍时间 查询出表中某人参与的所有车辆的最新的一条的竞价记 ...

  9. sql查询,如果有更新时间则按更新时间倒序,没有则按创建时间倒序排列

    原文:sql查询,如果有更新时间则按更新时间倒序,没有则按创建时间倒序排列 ORDER BY IFNULL(update_time,create_time) DESC IFNULL(expr1,exp ...

随机推荐

  1. jQuery中怎么添加innerText、innerHtml(转)

    发现如果我在div或者其他非表单的标签中赋值,原本用普通的js就直接document.getElementById("id").innerHtml(或者其他几个)就可以了. 但是在 ...

  2. [原]Fedora Linux环境下的应用工具总结

    一.办公类软件 1.Office办公:WPS 二.网络通信类软件 1.浏览器:Chrome 2.远程桌面:rdesktop(适用于Windows系列) 三.操作系统设置与优化 1.3D桌面管理:Com ...

  3. matlab 画三维图函数

    matlab三维绘图 http://blog.sina.com.cn/s/blog_6d5ffd0d0100lyah.html Matlab绘图系列之高级绘图 http://blog.163.com/ ...

  4. HackerRank "Kundu and Tree" !!

    Learnt from here: http://www.cnblogs.com/lautsie/p/3798165.html Idea is: we union all pure black edg ...

  5. bzoj3521: [Poi2014]Salad Bar

    Description 有一个长度为n的字符串,每一位只会是p或j.你需要取出一个子串S(从左到右或从右到左一个一个取出),使得不管是从左往右还是从右往左取,都保证每时每刻已取出的p的个数不小于j的个 ...

  6. Centos7安装Zabbix3.0

    1.安装服务器端包 #rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch. ...

  7. Highcharts 功能强大、开源、美观、图表丰富、兼容绝大多数浏览器的纯js图表库

    http://www.hcharts.cn/index.php 暂无介绍,等待后续补充

  8. s3c2440存储控制器和地址以及启动的理解

    转自:http://blog.sina.com.cn/s/blog_5ddb672b0100fkcf.html 1.首先应该先了解Flash ROM的种类 NOR FLASH地址线和数据线分开,来了地 ...

  9. PLSQL_性能优化系列16_Oracle Tuning Analyze优化分析

    2014-12-23 Created By BaoXinjian

  10. hdu 3068 最长回文 manacher算法(视频)

    感悟: 首先我要Orz一下qsc,我在网上很难找到关于acm的教学视频,但偶然发现了这个,感觉做的很好,链接:戳戳戳 感觉这种花费自己时间去教别人的人真的很伟大. manacher算法把所有的回文都变 ...