问题如下:每个业主下面有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