您的位置:首页 > 数据库

sql语句收集之一

2004-06-25 08:20 218 查看
有一表(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 寝室号 ?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: