开发者

Sort a query by a varchar field(which have numerical values) on numerical basis with Jooq

How can i sort a varchar field , i have taken ID as varchar and i want to sort it numerically.

We can do this in SQL with using

sql query ... order by 0+id desc

What i have in Jooq is

SimpleSelectFinalStep<ScoreCardRecord> q = factory.selectFrom(ScoreCard.SCORE_CARD)
                    .order开发者_C百科By(OloScoreCard.SCORE_CARD_ID.descending())
                    .limit(0,1);


Have you tried casting your VARCHAR field into a numeric DataType? You could do it like this:

factory.selectFrom(ScoreCard.SCORE_CARD)
       .orderBy(OloScoreCard.SCORE_CARD_ID.cast(Integer.class).descending())
       .limit(0, 1);

That way you could omit using "plain SQL fields"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜