请邹建帮忙!
qunw 2004-06-22 08:44:38 你好!邹建大哥!
看了你的文章:对下面的不太明白!
有一表(room):
寝室号 char 4
姓名 nchar 4
现在要求写一句sql语句,使的查询后的集合格式为:
-------------------------------------------------------------------------
寝室号 成员一 成员二 成员三 成员四 成员五 成员六 成员七 成员八
-------------------------------------------------------------------------
若一个寝室的成员不足八人,让多余的字段为空
------------------------------------------------------------------------------------
select 寝室号
,成员一=max(case id when 1 then 姓名 end)
,成员二=max(case id when 2 then 姓名 end)
,成员三=max(case id when 3 then 姓名 end)
,成员四=max(case id when 4 then 姓名 end)
,成员五=max(case id when 5 then 姓名 end)
,成员六=max(case id when 6 then 姓名 end)
,成员七=max(case id when 7 then 姓名 end)
,成员八=max(case id when 8 then 姓名 end)
from(
select 寝室号,姓名,id=(
select count(*) from room
where 寝室号=a.寝室号
and 姓名<=a.姓名)
from room a
)a group by 寝室号
请问: "姓名<=a.姓名" 为什么要这么写!是什么意思!这里不太懂!