完了,我脑海里一直是killygirl (开心女孩) 这几个字,什么同学寝室的,我不知道了!
解决方案 »
- 有一个表结构见里,表结构比较简单,请问如何求出下面的结果,具体请见里,不知如何写sql语句,万分感谢!
- 求SQL语句,求每两行间某字段的最小差距
- sql数据复杂查询,请帮忙。
- 一個SQL查詢問題,立即解決,立即給分
- SQL语句创建表格时出问题了,麻烦各位帮忙看看,很急,谢谢啦
- 在表中新增一个列,怎样写sql新增?要可以指定这个列的顺序.
- 菜鸟初学问题,两个表对应字段比较的SQL如何写……100分,及时揭帖
- MS SQL Server 2000企业版安装后,为何里面没有例子数据库?
- 如何在sqlserver的定时任务中得到批处理执行后的返回值?
- oracle中如何做个类似于自动编号的字段
- 高手帮忙,我想景象自动统计
- 问一个小问题……应该酸是update的问题
declare @i int,@j int
select @i=0,@j=0update 学生表 set @i=case @j when 3 then @i+1 else @i end
,@j=case @j when 3 then 0 else @j+1 end
,寝室号=@i
where 性别='男'select @j=0,@i=@i+1
update 学生表 set @i=case @j when 3 then @i+1 else @i end
,@j=case @j when 3 then 0 else @j+1 end
,寝室号=@i
where 性别='女'
寝室号分别是1xxx,2xxx
create table 表(学号 char(3),姓名 varchar(10),性别 char(2),寝室 char(4))
insert 表 select '001','赵平','男',null
union all select '002','王非','女',null
union all select '003','李六','男',null
union all select '004','李五','男',null
union all select '005','张六','女',null
union all select '006','张五','女',null
union all select '007','张四','男',null
union all select '008','李四','女',null
union all select '009','张三','女',null
go--更新参数定义
declare @step int
set @step=2 --这个2表示每两个人一个寝室--更新处理
declare @i int,@j int--先处理男生的
select @i=2001,@j=0update 表 set @i=case @j when @step then @i+1 else @i end
,@j=case @j when @step then 1 else @j+1 end
,寝室=@i
where 性别='男'--再处理女生的
select @i=1001,@j=0update 表 set @i=case @j when @step then @i+1 else @i end
,@j=case @j when @step then 1 else @j+1 end
,寝室=@i
where 性别='女'
go--显示处理结果
select * from 表 order by 寝室,性别
go--删除测试
drop table 表/*--测试结果
学号 姓名 性别 寝室
---- ---------- ---- ----
002 王非 女 1001
005 张六 女 1001
006 张五 女 1002
008 李四 女 1002
009 张三 女 1003
001 赵平 男 2001
003 李六 男 2001
004 李五 男 2002
007 张四 男 2002(所影响的行数为 9 行)
--*/