简单的数据库面试题
1 表 table 查询 拥有2个以上ID的NAME
ID NAME
1, 'A'
2, 'A'
3, 'B'
4, 'B'
5, 'D'
6, 'E'
7, 'F'
方法1
SELECT distinct tt.name FROM `table` as t,`table` as tt where tt.name=t.name and tt.id<>t.id;
方法2
SELECT distinct name FROM `table` t where exists(select * from `table` tt where t.name=tt.name and tt.id<>t.id);
2 查询第几列,或者多少到多少
mysql: limit ?,?
sqlserver: top , not in