日期:2014-05-17  浏览次数:20766 次

一个对于我来说很难的问题,郁闷了几天的,大哥大姐们帮帮忙吧!
问题如下:数据库中有表   num_table   表中有记录如下:
字段:    
NID         N_Time             N_Num
-----------------------------
2007         10:10:00           a
2007         10:02:00           a
2007         10:01:00           a
2006         09:22:00           b
2006         09:20:00           b
2005         08:20:00           c
------------------------------
问题是想在也面中输出一个表格,想要得到的结果如下:
┎───┯──────┯────┒
│2007     │10:10:00  │    │
┖───────────    │
│2007 │10:02:00  │ a           │就是把NID相同的N_Num的单元格合并
┖───────────    │
│2007 │10:02:00  │    │
┖───────────────┚
│2006 │09:22:00  │    │
┖───────────     b           │
│2006 │09:20:00  │    │
┖───────────────┚
│2005 │08:20:00  │ c     │
┖───────────────┚

写这个表好久哦,不知道大家看明白了吗?就是把数据中NID相同的对应的N_Num的单元格合并,不管大家用什么方法,只要能实现上面的表格就好。小生在此谢过了!




------解决方案--------------------
set rs=conn.execute( "select NID,N_Time,N_Num,(select count(NID) from num_table where N_Num=a.N_Num group by N_Num) as N_Count from num_table as a order by N_Num ")
NowNum= " "
do while not rs.eof
response.write " <tr> <Td> NID </td> <td> N_Time </td> "
if NowNum <> rs( "N_Num ") then
NowNum=rs( "N_Num ")
response.write " <td rowspan= "&rs( "N_Count ")& "> N_Num </td> "
end if
response.write " </tr> "
rs.movenext
loop
------解决方案--------------------
<%
set conn=server.CreateObject( "adodb.connection ")
str= "driver={microsoft access driver (*.mdb)};dbq= " & server.MapPath( "示例.mdb ")
conn.open str
sql= "select N_NUM,count(*) as num from demo group by N_NUM order by N_NUM "
set rs=conn.execute(sql)
dim n(),num()
i=0
do while not rs.eof
redim preserve n(i) '用于统计有多少个相同的N_NUM
redim preserve num(i) '同时记下N_NUM的内容
n(i)=rs( "num ")
num(i)=rs( "N_NUM ")
i=i+1
rs.movenext
loop
sql= "select * from demo order by N_NUM "
set rs=conn.execute(sql)
response.write " <table border=1> "
i=0:j=0
do while not rs.eof
response.Write( " <tr> ")
response.Write " <td> " & rs( "NID ") & " </td> "
response.Write " <td> " & rs( "N_TIME ") & " </td> "
if j=0 then response.Write " <td rowspan= " & n(i) & "> " & num(i) & " </td> "
if rs( "N_NUM ") <> num(i) then
i=i+1
response.Write " <td rowspan= " & n(i) & "> " & num(i) & " </td> "
end if
rs.movenext
j=j+1
response.Write( " </tr> ")
loop
response.Write( " </table> ")
set conn=nothing
%&g