我现有数据库如下
ID 地点 气温
1 上海 30
2 31
3 31
4 北京 25
5 26能用什么语句实现下面内容ID 地点 气温
1 上海 30
2 上海 31
3 上海 31
4 北京 25
5 北京 26
ID 地点 气温
1 上海 30
2 31
3 31
4 北京 25
5 26能用什么语句实现下面内容ID 地点 气温
1 上海 30
2 上海 31
3 上海 31
4 北京 25
5 北京 26
解决方案 »
- SQL 里面自带的事件跟踪器 如何跟踪到某个IP对某几个表所有的事件
- 请问兄弟们,bcp复制对应的格式文件.fmt是如何生成的?谢谢大家了!!!!!!!!!!!
- 如何用语句将自动标识列的自动标识属性去掉?
- 高分求解SQL
- 编写一个触发器,如果std_score表中Place不为空,则不允许删除本条记录。
- 求解一道sql语句
- 我用的sql server 7.0,现在C盘根目录下有一个sql.log文件,文件大约有1个G,并且不停地增长,我的硬盘空间已不够了,请问这个文件有何作用
- mysql 5.0.16版本配置启动报错误。很奇怪
- 请问怎么在sqlserver的用户子定义中是用循环啊!
- 如何将表中列为text类型的内容通过CSV全部导出来
- 菜鸟请教sql存储过程
- 关于GETDATE()的转换
declare @t table(id int,地点 varchar(10),气温 int)
insert @t
select 1,'上海',30
union all
Select 2,null,31
union all
Select 3,null,31
union all
Select 4,'北京',25
union all
Select 5,null,26Select id,isnull(地点,(Select top 1 地点 from @t where 地点 is not null and id<a.id order by id desc)),气温 from @t a
drop table tb create table tb (tid int ,address varchar(10),qiwen varchar(4) )insert into tb (tid,address,qiwen) values (1,'上海','30')
insert into tb (tid,address,qiwen) values (2,'','30')
insert into tb (tid,address,qiwen) values (3,'','30')
insert into tb (tid,address,qiwen) values (4,'','30')
insert into tb (tid,address,qiwen) values (5,'','30')
insert into tb (tid,address,qiwen) values (6,'北京','30')
insert into tb (tid,address,qiwen) values (7,'','30')
insert into tb (tid,address,qiwen) values (8,'','30')
insert into tb (tid,address,qiwen) values (9,'天津','30')
insert into tb (tid,address,qiwen) values (10,'','30')
insert into tb (tid,address,qiwen) values (11,'','30')
insert into tb (tid,address,qiwen) values (12,'','30')
select * from tb
/********** 下面程序 *******************/
/***********开始 ****************/declare @tid int
set @tid=2
while @tid<= 12 -- 12是数据表里ID的最大值。
begin
if exists ( select tid from tb where address='' and tid=@tid )
update tb set tb.address=a.address from tb ,(select tid,address from tb where tid=@tid-1) a
where tb.tid=@tid
set @tid=@tid+1
end/*************结束 *******************/
TID---ADDRESS--QIWEN
1 上海 30
2 上海 30
3 上海 30
4 上海 30
5 上海 30
6 北京 30
7 北京 30
8 北京 30
9 天津 30
10 天津 30
11 天津 30
12 天津 30