当前位置: 代码迷 >> ASP >> 关于按照用户名分组的有关问题
  详细解决方案

关于按照用户名分组的有关问题

热度:92   发布时间:2012-03-09 21:42:55.0
关于按照用户名分组的问题
问题如下:每个业主下面有3-5套房屋,我想先按照业主分组,然后再显示其对应的房源,代码如下:
select   *   from   room     order   by       username     desc

其中username代表业主字段,我不大会用group,请问各位高手应该怎样写呢?

我想按照用户名来分组,应该怎样写?

------解决方案--------------------
select * from room group by username
------解决方案--------------------
select username from room group by username
------解决方案--------------------
select * from dfzx where flag_id=1 and flag2=1 and lan=0 and city_y_char= '上海市 ' group by username_y_char order by city_y_char,area_y_char desc
------解决方案--------------------
方法一:

select * from dfzx where flag_id=1 and flag2=1 and lan=0 and city_y_char= '上海市 ' order by username_y_char, city_y_char,area_y_char desc
........
username= " "
do while not rs.eof
if username <> rs( "username ") then
输出用户
输出房子
else
输出房子
end if
rs.movenext
loop
..........
....
...

方法二:
select * from dfzx where flag_id=1 and flag2=1 and lan=0 and city_y_char= '上海市 ' and (id IN (SELECT MAX(id) FROM dfzx GROUP BY username)) order by city_y_char,area_y_char desc
do while not rs.eof
....................
................
select * from dfzx where flag_id=1 and flag2=1 and lan=0 and city_y_char= '上海市 ' and username= ' "&rs( "username ")& " ' order by city_y_char,area_y_char desc
do while not rs2.eof

输出房子

rs2.movenext
loop
..........
....
...
rs.movenext
loop
  相关解决方案