我想做个户籍表,有成员id1,户口本id2
几个不同的id1有相同的id2,id2是随机固定位数的数字
现在想做个查询,循环输出所有户口信息,不想重复,
sql该怎么写?
举例:
id1 id2 姓名
1 001 a
2 001 b
3 001 c
4 123 d
5 123 e
...
1023 374 x
1024 374 y
dim sql,rs,c
c=""
sql="select * from hjb order by id2 asc"
set rs=conn.execute(sql)
do while not rs.eof then
if rs("id2")<>c then
response.write rs("id2")&"户口信息"
end if
response.write rs("姓名")
c=rs("id2")
loop
set rs=conn.execute("select distinct id2 from hjb order by id2 asc")
if not rs.eof then
do while not rs.eof
response.write rs(0)&"户口信息:<br>"
set rs1=conn.execute("select 姓名 from hjb where id2='"&rs(0)&"'")
do while not rs1.eof
response.write rs1(0)
response.write "<br>"
rs1.movenext
loop
rs.movenext
loop
end if