当前位置:网站首页>mysql报错ORDER BY clause is not in SELECT list, references column ‘‘which is not in SELECT list解决方案
mysql报错ORDER BY clause is not in SELECT list, references column ‘‘which is not in SELECT list解决方案
2022-07-08 01:13:00 【时间是一种解药】
mysql报错Expression #1 of ORDER BY clause is not in SELECT list, references column 'fusion.m.create_time' which is not in SELECT list; this is incompatible with DISTINCT解决方案
问题背景
在进行多表关联出现报错:Expression #1 of ORDER BY clause is not in SELECT list, references column ‘fusion.m.create_time’ which is not in SELECT list; this is incompatible with DISTINCT,原因是有个字段的order by排序和distinct不兼容
解决方案
1 首先在xml的distinct去重去除
2 把所有查出来的数据在程序里面进行单独去重,一般查出来的都是list<对象>类型,根据对象里面的某一个字段进行去重,可以使用流来进行操作
- 保持原有的顺序进行去重
public class StreamUtils{
//LinkedHashMap有序去重
private static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
LinkedHashMap<Object, Boolean> map = new LinkedHashMap<>();
return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
//ConcurrentHashMap无序去重
private static <T> Predicate<T> distinctByKeyMap(Function<? super T, Object> keyExtractor) {
ConcurrentHashMap<Object, Boolean> map = new ConcurrentHashMap<>();
return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
}
List<User> list = new ArrayList<User>();
list.add(new User("小南", 23, "18335888888"));
list.add(new User("小南", 22, "18335888888"));
list.add(new User("小南", 21, "18335888888"));
list.add(new User("小南", 20, "18335888888"));
list = list.stream().filter(StreamUtils.distinctByKey(User :: getName)).collect(Collectors.toList());
System.out.println(list.toString());
- 去重之后变成乱序
List<User> userList = new ArrayList();
userList.add(new User("yuange", 12));
userList.add(new User("yuange", 12));
userList.add(new User("yuange1", 14));
userList.add(new User("yuange1", 15));
userList.add(new User("pangpang", 12));
userList.add(new User("pangpang", 12));
List<User> result = userList.stream()
.collect(collectingAndThen(toCollection(() ->
new TreeSet<>(comparing(User::getName))), ArrayList::new));
result.forEach(System.out::println);
总结
看过别人的一些解决方案,一般是更改数据库配置,或者使用聚合函数,但我都无效,所以使用自己的方式
作为程序员第 195 篇文章,每次写一句歌词记录一下,看看人生有几首歌的时间,wahahaha …


Lyric: 谁说拍中国风 一定要配灯笼
边栏推荐
- In depth analysis of ArrayList source code, from the most basic capacity expansion principle, to the magic iterator and fast fail mechanism, you have everything you want!!!
- 力争做到国内赛事应办尽办,国家体育总局明确安全有序恢复线下体育赛事
- burpsuite
- C language -cmake cmakelists Txt tutorial
- Leetcode question brushing record | 283_ Move zero
- leetcode 866. Prime Palindrome | 866. 回文素数
- EMQX 5.0 发布:单集群支持 1 亿 MQTT 连接的开源物联网消息服务器
- leetcode 866. Prime Palindrome | 866. prime palindromes
- XXL job of distributed timed tasks
- Common disk formats and the differences between them
猜你喜欢
![[reinforcement learning medical] deep reinforcement learning for clinical decision support: a brief overview](/img/45/5f14454267318bb404732c2df5e03c.jpg)
[reinforcement learning medical] deep reinforcement learning for clinical decision support: a brief overview

Deep understanding of softmax

Random walk reasoning and learning in large-scale knowledge base

JVM memory and garbage collection-3-object instantiation and memory layout

excel函数统计已存在数据的数量

数据链路层及网络层协议要点

Spock单元测试框架介绍及在美团优选的实践_第四章(Exception异常处理mock方式)

Mqtt x newsletter 2022-06 | v1.8.0 release, new mqtt CLI and mqtt websocket tools

很多小伙伴不太了解ORM框架的底层原理,这不,冰河带你10分钟手撸一个极简版ORM框架(赶快收藏吧)

1331:【例1-2】后缀表达式的值
随机推荐
需要思考的地方
[knowledge map paper] Devine: a generative anti imitation learning framework for knowledge map reasoning
Force buckle 6_ 1342. Number of operations to change a number to 0
Can you write the software test questions?
[recommendation system paper reading] recommendation simulation user feedback based on Reinforcement Learning
Spock单元测试框架介绍及在美团优选的实践_第四章(Exception异常处理mock方式)
Deep understanding of softmax
Introduction to Microsoft ad super Foundation
Little knowledge about TXE and TC flag bits
Xmeter newsletter 2022-06 enterprise v3.2.3 release, error log and test report chart optimization
【每日一题】648. 单词替换
Nanny level tutorial: Azkaban executes jar package (with test samples and results)
VIM use
Unity 射线与碰撞范围检测【踩坑记录】
Anan's judgment
cv2-drawline
分布式定时任务之XXL-JOB
Infrared dim small target detection: common evaluation indicators
Beaucoup d'enfants ne savent pas grand - chose sur le principe sous - jacent du cadre orm, non, ice River vous emmène 10 minutes à la main "un cadre orm minimaliste" (collectionnez - le maintenant)
生命的高度