当前位置:网站首页>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: 谁说拍中国风 一定要配灯笼
边栏推荐
- Vim 字符串替换
- Semantic segmentation | learning record (4) expansion convolution (void convolution)
- Deeppath: a reinforcement learning method of knowledge graph reasoning
- PHP calculates personal income tax
- Coreldraw2022 download and install computer system requirements technical specifications
- 常见的磁盘格式以及它们之间的区别
- 银行需要搭建智能客服模块的中台能力,驱动全场景智能客服务升级
- Deep understanding of softmax
- Key points of data link layer and network layer protocol
- Relationship between bizdevops and Devops
猜你喜欢
Gaussian filtering and bilateral filtering principle, matlab implementation and result comparison
1331:【例1-2】后缀表达式的值
List of top ten domestic industrial 3D visual guidance enterprises in 2022
Spock单元测试框架介绍及在美团优选的实践_第三章(void无返回值方法mock方式)
很多小伙伴不太了解ORM框架的底层原理,这不,冰河带你10分钟手撸一个极简版ORM框架(赶快收藏吧)
See how names are added to namespace STD from cmath file
Give some suggestions to friends who are just getting started or preparing to change careers as network engineers
Discrimination gradient descent
Kwai applet guaranteed payment PHP source code packaging
Ml backward propagation
随机推荐
MQTT X Newsletter 2022-06 | v1.8.0 发布,新增 MQTT CLI 和 MQTT WebSocket 工具
Semantic segmentation | learning record (3) FCN
JVM memory and garbage collection-3-runtime data area / heap area
Emqx 5.0 release: open source Internet of things message server with single cluster supporting 100million mqtt connections
阿南的判断
Kwai applet guaranteed payment PHP source code packaging
VIM use
metasploit
Clickhouse principle analysis and application practice "reading notes (8)
电路如图,R1=2kΩ,R2=2kΩ,R3=4kΩ,Rf=4kΩ。求输出与输入关系表达式。
Give some suggestions to friends who are just getting started or preparing to change careers as network engineers
1331:【例1-2】后缀表达式的值
Coreldraw2022 download and install computer system requirements technical specifications
Talk about the cloud deployment of local projects created by SAP IRPA studio
Spock单元测试框架介绍及在美团优选的实践_第三章(void无返回值方法mock方式)
BizDevOps与DevOps的关系
Nanny level tutorial: Azkaban executes jar package (with test samples and results)
Monthly observation of internet medical field in May 2022
力扣4_412. Fizz Buzz
Thread deadlock -- conditions for deadlock generation