间接语句SQL codeCnoCpno152NULL3146576NULL7686查询每一个cno的间接cpnoPS:就是1对应5,5对应7,那么1间接
间接语句
- SQL code
Cno Cpno1 52 NULL3 14 65 76 NULL7 68 6
查询每一个cno的间接cpno
PS:就是1对应5,5对应7,那么1间接对应7.(一张表中)
还有个问题就是一张表中有N条一模一样的数据,如何删除只剩下一条。
坐等。
[解决办法]
1,就是将表join两次。
2,select distinct * from tb
[解决办法]
- SQL code
create table tb(cno int, Cpno int)insert into tb values(1 , 5)insert into tb values(2 , NULL)insert into tb values(3 , 1)insert into tb values(4 , 6)insert into tb values(5 , 7)insert into tb values(6 , NULL)insert into tb values(7 , 6)insert into tb values(8 , 6)goselect t1.cno , cpno = (select cpno from tb t2 where t2.cno = t1.cpno) from tb t1/*cno cpno ----------- ----------- 1 72 NULL3 54 NULL5 66 NULL7 NULL8 NULL(所影响的行数为 8 行)*/select * from ( select t1.cno , cpno = (select cpno from tb t2 where t2.cno = t1.cpno) from tb t1) twhere cpno is not null/*cno cpno ----------- ----------- 1 73 55 6(所影响的行数为 3 行)*/drop table tb
