关于所写的两个简单sql 循环语句的疑问
来源:互联网 发布:淘宝为什么不能买彩票 编辑:程序博客网 时间:2024/05/22 13:36
有两张表 ms ,xhl_doi_2015 , 其中 ms 表中的 字段 fenleihao 包含 xhl_doi_2015 表中的pacs ,我想实现的结果是 统计 ms表中 xhl_doi_2015表中各个pacs出现的次数,并将该次数 写到 xhl_doi_2015 的 tougao 字段中。
其中xhl_doi_2015 表结构如下:
sql1,
declare @id int
declare @maxid int
declare @minid int
declare @count int
select @maxid= max(a.id) from xhl_doi_2015 a where tougao is null
select @minid= min(a.id) from xhl_doi_2015 a where tougao is null
if ((@maxid is not null) and (@minid is not null))
begin
while (@maxid>=@minid)
begin
select @count=count(a.id)
from ms b ,xhl_doi_2015 a
where b.pacs like '%'+a.pacs+'%' and a.id=@minid and a.tougao is null
update xhl_doi_2015 set tougao=@count where id=@minid and tougao is null
select @minid= min(a.id) from xhl_doi_2015 a where tougao is null
end
end
go
sql2
declare @id int
declare @maxid int
declare @minid int
declare @count int
declare @pacs int
select @maxid= max(a.id) from xhl_doi_2015 a where tougao is null
select @minid= min(a.id) from xhl_doi_2015 a where tougao is null
while (@maxid>=@minid)
begin
select @pacs=min(pacs) from xhl_doi_2015 where id=@minid and tougao is null
select @count =count(id) from ms where fenleihao like '%'+@pacs+'%'
update xhl_doi_2015 set tougao=@count where id=@minid and tougao is null
select @minid= min(a.id) from xhl_doi_2015 a where tougao is null
end
go
实际测试中,游标1将实际数据写到了xhl_doi_2015 的tougao字段中,但游标2 执行后,xhl_doi_2015 表的投稿字段,全都被 update 为 0 。
但我觉的 游标2的 逻辑应该也没错,但不知道为什么 结果都是0那。
- 关于所写的两个简单sql 循环语句的疑问
- 两个简单的循环
- 关于标准C++编译器的两个疑问
- 简单的循环语句
- 写了个有史以来我所写过的最复杂的sql语句
- for循环的疑问
- 关于读简单配置文件的疑问
- T-SQL流程控制语句:两个简单的求和练习
- PL/SQL的循环语句
- SQL循环语句 的写法
- Oracle 数据库判断所写的SQL语句的执行效率
- 关于循环语句的运用
- 关于Windows中的系统消息循环占用CPU的疑问
- 关于写SQL语句
- 简单的SQL语句
- 简单的SQL语句
- 简单的SQL语句
- 简单的sql语句。
- hdu 5167 Fibonacci(DFS)
- JAVA NIO 实例
- Android特效 五种Toast详解
- JAVA中sleep()、wait()、yield()、join()方法浅析
- avrisp mkii对目标电路的影响
- 关于所写的两个简单sql 循环语句的疑问
- Android ListView不响应OnItemClickListener解决办法
- 【learning opencv】01.图像的显示(C++版本)
- 提升移动设备响应式设计的8个建议
- Android杂谈--打开文件的Intent及使用
- 假分数样式标注
- loading页面加载用
- NSStirng临时对象
- Algorithm Gossip: 阿姆斯壮数