2018年10月19日面试的2道题目

1.for和foreach的区别
2.给一个表table, 字段id(主键), userId,查询userId相同值大于3的所有数据

for适合于有固定数量的集合,可以做删除,添加操作

foreach是for的简化版本,实际上是调用了Iterator, 适合于没有实现randomaccess接口,实现了iterator接口的类。遍历时不能做添加或删除操作,否则会报java.util.ConcurrentModificationException

2.select t1.id, t1.userId from t as t1
where (
select count(1) from t as t2 where t1.userId = t2.userId
) > 3

记录一下,当时知道部分,但没写完全

猜你喜欢

转载自blog.csdn.net/zhanglinlove/article/details/83211421