1、要把以下的一段sql转换成为java语句
SELECT DISTINCT
c.company_code AS companyCode,
c.user_name AS userName
FROM user AS c
WHERE CHAR_LENGTH(c.user_name) = 11 AND c.user_name LIKE '1%'
AND NOT EXISTS (SELECT 1 FROM temp_phone AS p WHERE p.phone = c.user_name)
2、起初我用的查询如下,发现结果与SQL执行结果数据量出现了很大的差异,结果发现likeLeft("user_name", "1")并不能替换c.user_name LIKE '1%'
public List<User> getUserList(List<String> phoneList) {
return this.list(new QueryWrapper<User>()
.likeLeft("user_name", "1")
.eq("CHAR_LENGTH(user_name)", 11)
.notIn("user_name", phoneList));
}
3、于是最后修改为
public List<User> getUserList(List<String> phoneList) {
List<User> userList = this.list(new QueryWrapper<User>() .eq("CHAR_LENGTH(user_name)", 11)
.notIn("user_name", phoneList));
return userList.stream().distinct().filter(user -> user.getUserName().startsWith("1")).collect(Collectors.toList());
}
4、至于为什么likeLeft("user_name", "1")不能替换c.user_name LIKE '1%',likeLeft到底是个什么情况还在研究中,记录一下,研究好了再来补上