Java Criteria API – 如何使用MySQL的ANY_VALUE

huangapple go评论113阅读模式
英文:

Java Criteria API - how to use MySQL's ANY_VALUE

问题

Is there any way to use Mysql ANY_VALUE in Criteria API?

I cant find any useful method in CriteriaBuilder, CriteriaQuery etc.

What i want achieve:

SELECT cartID, date, ANY_VALUE(customerName) FROM table WHERE type='A' GROUP BY cartID, date;

Why i need it? Because i dont want to add customerName to GROUP By clause ( its may be different for each row)

EDIT: I managed to do what i wanted by changing ANY_VALUE to MAX clause + if i want to ORDER BY customerName i need also to include MAX eg: 'ORDER BY MAX(customerName)

英文:

Is there any way to use Mysql ANY_VALUE in Criteria API?

I cant find any useful method in CriteriaBuilder, CriteriaQuery etc.

What i want achieve:

SELECT cartID, date, ANY_VALUE(customerName) FROM table WHERE type='A' GROUP BY cartID, date;

Why i need it? Because i dont want to add customerName to GROUP By clause ( its may be different for each row)

EDIT: I managed to do what i wanted by changing ANY_VALUE to MAX clause + if i want to ORDER BY customerName i need also to include MAX eg: 'ORDER BY MAX(customerName)

答案1

得分: 0

我成功地通过将ANY_VALUE更改为MAX子句来实现我想要的,如果我想按customerName排序,还需要包括MAX,例如:'ORDER BY MAX(customerName)。

英文:

I managed to do what i wanted by changing ANY_VALUE to MAX clause + if i want to ORDER BY customerName i need also to include MAX eg: 'ORDER BY MAX(customerName)

huangapple
  • 本文由 发表于 2020年7月28日 14:47:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63128454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定