--方法(一):分组排练进行更新
----------------------------------------------------------------------------------------------------------------
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. .Net HttpPost的发送和接收示例代码

    /// <summary> /// 模拟http 发送post或get请求 /// </summary> /// <param name="Url"& ...

  2. RMAN备份数据库与恢复数据库(整库)

    1 准备 2 1.1 检查数据库归档状态 2 1.2 RMAN登陆目标 2 2 备份全库 2 2.1 创建备份数据存储目录 2 2.2 RMAN备份全库 2 2.3 试验(备份后,改变数据) 5 2. ...

  3. R(五): R常用函数

    工作笔记记录,会持续更新.... 目录: apply tapply lapply sapply merge substr.substring.strsplit.unlist.paste.paste0. ...

  4. taglib例子

    jsp中的taglib有点类似asp.net中的customer control.自定义标签. 一个最简单的taglib使用例子:检查用户是否已经被登陆. 新建一个class: CheckLoginT ...

  5. RDO部署openstack(1)

    1. 安装系统CentOS 6.5   2. 网络配置   Eth0 设置 # cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ON ...

  6. IntelliJ IDEA中如何设置同时打开多个文件且分行显示?

    Window→Editor Tabs→Tabs Placement→Show Tabs in Single Row 取消选中后即可在多行显示 下图为实际显示效果:  还可以自行设置打开文件窗口数(默认 ...

  7. Python类,域,方法,对象,继承

    类和对象: 是面向对象编程的两个主要方面,类创建一个新类型,而对象这个类的实例.. 域: 属于一个对象或类的变量被称为域.域有两种类型: 属于每个实例(类的对象)或属于类本身.它们分别被称为实例变量和 ...

  8. Linux进程内存分析pmap命令(转)

    名称:       pmap - report memory map of a process(查看进程的内存映像信息)用法       pmap [ -x | -d ] [ -q ] pids... ...

  9. Spark参数配置说明

    1  修改$SPARK_HOME/conf目录下的spark-defaults.conf文件 添加以下配置项 spark.sql.hive.convertMetastoreParquet       ...

  10. RAC_Oracle集群服务安装Grid Infrastructure(案例)

    2015-01-24 Created By BaoXinjian Thanks and Regards