两道SQL笔试题:一:表Test 中,找出文件夹下有文件的文件夹Table Test
path isfolder
/music/ T
/music/a.jpg F
/pic/ T
/pic/b.jpg F
/mnt/ T
期望结果:
/music/
/pic/
SQL语句:
select a.path from
(select * from Test where isfolder='T') a
join
(select * from Test where isfolder='F') b
on
(b.path like concat(a.path,'%'))
测试用的是Mysql,oracle的话,值需要将on条件换成:(b.path like a.path || '%')
二:删除一张没有主键和Unique约束的重复记录
Table Test
A B C
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
3 3 3
4 4 4
期望结果:
A B C
1 1 1
2 2 2
3 3 3
4 4 4
SQL语句:
采用临时表
create table tmp as
select distinct * from Test;
drop table Test;
rename tmp to Test
select * from Test