[SQL]分组排练进行更新
--方法(一):分组排练进行更新
----------------------------------------------------------------------------------------------------------------
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]分组排练进行更新的更多相关文章
- 取SQL分组中的某几行数据
取SQL分组中的某几行数据 对表中数据分组,有时只需要某列的聚合值:有时却需要返回整行数据,常用的方法有:子查询.ROW_NUMBER.APPLY,总体感觉还是ROW_NUMBER比较直观.测试数据: ...
- sql 分组后显示每组的前几条记录
sql 分组后显示每组的前几条记录 如 表中记录是 code serialno A1 1 ...
- SQL分组查询及聚集函数的使用
今天要做一个查询统计功能,一开始有点犯难,上午尝试大半天才写出统计sql语句,才发现自己sql分组查询及聚集函数没学好:其实就是group by子句和几个聚集函数,熟练使用统计功能很简单.在此总结下今 ...
- SQL批量添加,更新,删除
SQL语句: 存储过程: 代码: 这里说的是关于SQL的批量操作数据. 需要准备: 三层框架:利用 动软代码生成器(可以快速生成增删改查) 生成三层 Model,BLL,Dal ①DbHelpeSQL ...
- SQL中使用UPDATE更新数据时一定要记得WHERE子句
我们在使用 SQL 中的 UPDATE 更新数据时,一般都不会更新表中的左右数据,所以我们更新的数据的 SQL 语句中会带有 WHERE 子句,如果没有WHERE子句,就回更新表中所有的数据,在 my ...
- 数据库:sql 多表联合更新【转】
SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...
- Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
如何用一条sql语句实现批量更新?mysql并没有提供直接的方法来实现批量更新,但是可以用点小技巧来实现. 复制代码 代码如下: UPDATE mytable SET myfield = CASE i ...
- sql 分组后按时间降序排列再取出每组的第一条记录
原文:sql 分组后按时间降序排列再取出每组的第一条记录 竞价记录表: Aid 为竞拍车辆ID,uid为参与竞价人员ID,BidTime为参与竞拍时间 查询出表中某人参与的所有车辆的最新的一条的竞价记 ...
- sql查询,如果有更新时间则按更新时间倒序,没有则按创建时间倒序排列
原文:sql查询,如果有更新时间则按更新时间倒序,没有则按创建时间倒序排列 ORDER BY IFNULL(update_time,create_time) DESC IFNULL(expr1,exp ...
随机推荐
- adb uninstall/pull/push 命令的使用总结
uninstall的使用 adb uninstall package_name 卸载软件adb -k uninstall package_name 完全删除,包括data/data文件夹也删掉. pu ...
- smarty函数
内置函数(重要的几个): <{html_checkboxes name='nation' values=$code output=$name selected=$selid separator= ...
- maven本地仓库
引入某一个站点的jar包 <repositories> <repository> <id>maven.seasar.org</id> <name& ...
- 微信浏览器里location.reload问题
微信浏览器里location.reload问题会导致有时候post数据丢失.建议不要用此方式,尽量ajax方式获取或不要为了获取新的UI而刷新页面 2015-12-26 00:51:34array ( ...
- js为DIV动态设置id属性
<script> var objs=document.getElementById("iproduct").getElementsByTagName("div ...
- 在mui中遇到的内容覆盖导航栏的问题
一.问题描述: 公司项目中为了让内容以页面的形式显示,并要格式化页面内容,采用了百度的UEditor编辑器来显示内容,但是遇到了一个问题就是当下拉页面到一定距离之后,页面上方的导航栏会被内容遮盖. 二 ...
- POI按照源单元格设置目标单元格格式
原文:http://jjw198874.blog.163.com/blog/static/1889845522011102401854234/ POI按照源单元格设置目标单元格格式 poi按照一个源单 ...
- [tty与uart]2.tty和uart的函数调用流程
以下是在include/uapi/linux/tty.h中定义了现有的线规号,如果需要定义新的,则需要在后面添加新的 /* line disciplines */ #define N_TTY 0 #d ...
- [linux basic 基础]----线程的属性
在信号量和互斥量例子中,我们都是在程序推出之前利用pthread_join对线程进行再次同步:如果想让thread想创建它的线程返回数据我需要这么做:问题:我们有时候既不需要第二个线程向main线程返 ...
- 实现web数据同步的四种方式
http://www.admin10000.com/document/6067.html 实现web数据同步的四种方式 1.nfs实现web数据共享 2.rsync +inotify实现web数据同步 ...