分组数据填充

benqlch 2008-04-15 04:56:06
表:

姓名 组号 组序号
a
b
c
d
e
f
g
h
i
j
k
l


编写代码要求是:对人进行分组,5人一组,组序号是1,2,3,4,5 (如下)

姓名 组号 组序号
a 1 1
b 1 2
c 1 3
d 1 4
e 1 5
f 2 1
g 2 2
h 2 3
i 2 4
j 2 5
k 3 1
l 3 2
. . .
. . .
. . .

我是用DataGrid,如何实现啊!!!!
...全文
83 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
of123 2008-04-16
  • 打赏
  • 举报
回复
如果数据库表记录数不是 5 的倍数怎么办?

Set cn = New ADODB.Connectin
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=你的库文件名"
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM 表", cn, 3, 3

n = 0
Do Until rs.EOF
rs.组号 = n \ 5 + 1
rs.组序号 = (n Mod 5) + 1
rs.Update
rs.MoveNext
n = n + 1
Loop

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
benqlch 2008-04-16
  • 打赏
  • 举报
回复
我的数据库是access的
-晴天 2008-04-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 of123 的回复:]
n = 0
Do Until rs.EOF
rs.组号 = n \ 5 + 1
rs.组序号 = (n Mod 5) + 1
rs.Update
rs.MoveNext
n = n + 1
Loop
[/Quote]
算法错了!
-晴天 2008-04-15
  • 打赏
  • 举报
回复
--创建一个楼主已经有的表
create table tb1(name char(2))
insert into tb1 select 'a'
insert into tb1 select 'b'
insert into tb1 select 'c'
insert into tb1 select 'd'
insert into tb1 select 'e'
insert into tb1 select 'f'
insert into tb1 select 'g'
insert into tb1 select 'h'
insert into tb1 select 'i'
insert into tb1 select 'j'
insert into tb1 select 'k'
insert into tb1 select 'l'
insert into tb1 select 'm'
insert into tb1 select 'n'
insert into tb1 select 'o'
insert into tb1 select 'p'
insert into tb1 select 'q'
insert into tb1 select 'r'
insert into tb1 select 's'
insert into tb1 select 't'
insert into tb1 select 'u'
insert into tb1 select 'v'
insert into tb1 select 'w'

--下面是楼主想要做的事情
alter table tb1 add col1 int,col2 int, col3 int identity(1,1)
update tb1 set col1=floor((col3-0.5)/5)+1
update tb1 set col2=col3-(col1-1)*5
alter table tb1 drop column col3
select * from tb1

/*
name col1 col2
---- ----------- -----------
a 1 1
b 1 2
c 1 3
d 1 4
e 1 5
f 2 1
g 2 2
h 2 3
i 2 4
j 2 5
k 3 1
l 3 2
m 3 3
n 3 4
o 3 5
p 4 1
q 4 2
r 4 3
s 4 4
t 4 5
u 5 1
v 5 2
w 5 3

(23 行受影响)
*/
benqlch 2008-04-15
  • 打赏
  • 举报
回复
只要分组,以人的顺序无关,(关键是怎样把数据填充里表里)
zzyong00 2008-04-15
  • 打赏
  • 举报
回复
楼主,想想你自己要表达的意思!重写要求吧
不是大家不帮你,实在是理解能力有限啊
你要“对人进行分组”,怎么分?有没有规则?随机?姓名的拼音顺序?还是百家姓顺序?
波导终结者 2008-04-15
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20080414/15/47a1342b-7622-4eed-97f3-493c3178bcab.html

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧