日期:2014-05-20 浏览次数:20760 次
create table family ( id int, name varchar(10), parentId int ) insert into family values(1,"张三",5); insert into family values(2,"张四",5); insert into family values(3,"李三",6); insert into family values(4,"李四",NULL); insert into family values(5,"张_父",7); insert into family values(6,"李_父",8); insert into family values(7,"张_父_父",NULL); insert into family values(NULL,NULL,NULL); select * from family; --1、查有孙子的人 --2、查有父亲的人 --3、查没有父亲的人 --4、查名字中有下划线的人 --5、查出如下结构: --家族 人数 ------------ --张 4 --李 2 --李 1
--查有孙子的人 select id, name, parentId from family where id in (select parentId from family where id in (select parentId from family));--这个应该可以优化 --查有父亲的人 select id, name, parentId from family where parentId is not null; --查没有父亲的人 select id, name from family where parentId is null and name is not null; --查名字中有下划线的人 select id, name, parentId from family where name like '%\_%' escape '\' ;
------解决方案--------------------
接分...
------解决方案--------------------
端午已过、楼主可以结贴了
------解决方案--------------------
早上刚起来 接祝福
------解决方案--------------------
接祝福 jf
------解决方案--------------------
祝福。。。
------解决方案--------------------
散分就散分 出什么题撒
------解决方案--------------------
只喜欢接分,不喜欢做题
------解决方案--------------------
接分 ! 3Q !
------解决方案--------------------
接分,顺便学习下SQL