mxmai
2017-07-21 08:52:10 +08:00
三道题如下:
1.select * from t1 join t2 on t1.a = t2.a and t1.b = t2.b 和 select * from t1 left join t2 on t1.a = t2.a and t1.b = t2.b 这两个在结果集上有什么区别? ( 这个其实就是在问内连接和外连接的区别)
--
inner join 会返回满足关联条件的记录,而 left join 除了返回满足关联条件的记录外,还会返回基表(t1)中不满足关联条件的记录。
2.有一张表记录了用户登录的 ID 和时间,怎么找出每一个用户连续登录的天数?(这是个关于窗口函数的问题)
--
oracle 中有分析函数还知道大概怎么统计,mysql 刚想了下,是否可以用用户变量来统计(哭笑脸)
3.select count(a) from t1 和 select count(1) from t1 有什么区别?(null 的含义)
--
count、max、sum 等聚合函数会自动过滤 null 值,所以当 a 中含有 null 值时,count(a) != count(1),即 count(a) <= count(a)
ps, 刚才手贱发了一条,结果还不能删。