本文介绍了更新中的顺序号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这是对这里常见问题的一个小改动。我/ b 有一个包含sortorder的表格。用户可以在列中显示指定显示的记录的任意顺序。用户 有时会按照我们用来编号的方式排序记录 BASIC计划(10,20,30等)。我想做一个更新查询并修复 这样每个记录都按顺序排列。我在这个新闻组中找到了一个例子 如何做到这一点。 但是,我有一个小问题!有时,用户会复制 分拣机。所以例如,我可能有两个记录是 sortorder是20.我在这个新闻组中找到的查询在 中不起作用。这是一些代码,以便你可以看到我的意思。 创建表格sorttest( label char(5), sortorder int ) go insert sorttest values(''joe'',20) insert sorttest值(''dan'',10) 插入sorttest值(''jim'',44) 插入sorttest值(''tom'',20 ) 插入sorttest值(''jan'',50) - 数据转储 选择标签,排序顺序来自按排序顺序排序测试 - 我想修复所有的排序字段,以便它们是 顺序 update sorttest set sortorder =( select count(*) 来自sorttest子查询 其中sorttest。 sortorder< = subquery.sortorder ) - 请注意tom和joe有两个SORTORDER = 4 选择标签,sortorder从sortorder顺序排序 博士op table sorttest 提前感谢您的帮助。 解决方案 行和记录是完全不同的概念。你仍然想着一个文件系统,而不是RDBMS。行号是纸质表格或输入屏幕的物理 表示,而不是逻辑数据 模型元素。 Gee,你认为这可能是因为它们不是关系的b 验证或验证?并且 事实上你对这个愚蠢的列没有UNIQUE约束???? 您可能想阅读有关RDBMS的书籍,数据建模和分层 架构 this is a slight change to a fequently asked question around here. Ihave a table which contains a "sortorder" column where a user canspecify some arbitrary order for records to be displayed in. Usershave sometimes ordered records the way we used to number lines in aBASIC program (10,20,30, etc.). I''d like to do an update query and fixthis so that every record is in sequential order. I found an examplein this newsgroup of how to do this. However, I have a slight problem! Sometimes, the users duplicated thesortorders. So for example, I might have two records were thesortorder is 20. The query I found in this newsgroup does not work inthat case. Here is some code so that you can see what I mean. create table sorttest (label char(5),sortorder int)goinsert sorttest values (''joe'',20)insert sorttest values (''dan'',10)insert sorttest values (''jim'',44)insert sorttest values (''tom'',20)insert sorttest values (''jan'',50) -- data dumpselect label, sortorder from sorttest order by sortorder -- I''d like to fix all of the sortorder fields so that they aresequentialupdate sorttestset sortorder = (select count(*)from sorttest subquerywhere sorttest.sortorder <= subquery.sortorder) -- note that tom and joe BOTH HAVE SORTORDER = 4select label, sortorder from sorttest order by sortorder drop table sorttestThanks in advance for any help. 解决方案 Rows and records are totally diffreent concepts. You are stillthinking about a file system, not RDBMS. Line numbers are a physicalrepresentation of a paper form or input screen, not a logical datamodel element. Gee, do you suppose that might be due to the fact that they are notrelational, have no rules for validation or verifiication? And thefact that you do not have a UNIQUE constraint on this silly column???? You might want to read book on RDBMS, data modeling and tieredarchitectures 这篇关于更新中的顺序号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-20 22:56