随笔1:在一个表中操作数据

1、建立表

1 create table tb
2 (
3 id int identity(1,1),
4 name varchar(20),
5 fid int
6 )

2、插入数据

 

1 insert into tb(name,fid)values('a',0),('b',1)

3、查询表如下:

4、要求:根据id查询出表中的所有数据,并将与fid相同的id值后name插入查询的查询数据里面。

5、查询语句

1 select a.id,a.name,a.fid,b.name AS same from tb a,tb b where b.id=a.fid

6、得到结果:

 

 

 

 

 

posted @ 2013-04-18 15:36  nbyue  阅读(137)  评论(0)    收藏  举报