Question

I am using PlayFramework 2.2.2 with Ebean and MsSql.

I am looking for the simplest or cleanest method to be able to sort by MIN or MAX etc.

A sample raw sql query might look like:

SELECT id, name, tickets FROM users WHERE tickets != NULL ORDER BY MAX(tickets)

I don't know if it's just me, but the documentation for ebean is incredibly confusing. It seems any time anyone comes up with a query that couldn't be written by a 9 year old, the answer is "switch to RawSQL". Well, why bother with Ebean at all then?

Anyway, I would really like to see some CONCRETE Ebean examples of ordering by MIN/MAX, etc.

Was it helpful?

Solution

Do you really need order by min ,max... since there is id in the select list.

Let me know whether id is unique or duplicates are allowed

Would suggest to use the following query incase the id is unique

select id,name,tickets from users  where tickets is not null order by ticket desc

OTHER TIPS

I encountered the same problem then I found the following information.

Design Goal:

This query language is NOT designed to be a replacement for SQL. It is designed to be a simple way to describe the "Object Graph" you want Ebean to build for you. Each find/fetch represents a node in that "Object Graph" which makes it easy to define for each node which properties you want to fetch.

Once you hit the limits of this language such as wanting aggregate functions (sum, average, min etc) or recursive queries etc you use SQL. Ebean's goal is to make it as easy as possible to use your own SQL to populate entity beans. Refer to RawSql .

-> http://www.avaje.org/static/javadoc/pub/com/avaje/ebean/Query.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top