1

Recently, I wrote a program which is connection database!

I think that replace sql to querydsl;

For example SQL:

SELECT"MAX"(aa) AS big,"MIN"(aa) AS small FROM (
SELECT
    "TO_NUMBER"(MONITOR_INFO."VALUE") aa
FROM
    MONITOR_INFO
WHERE
    MONITOR_INFO.DSID IN (9211)
AND MONITOR_INFO."TIME" BETWEEN "TO_DATE" (
    '2013-09-03 00:00:00',
    'yyyy-mm-dd hh24:mi:ss'
)
AND TO_DATE (
    '2013-09-04 00:00:00',
    'yyyy-mm-dd hh24:mi:ss'
)
)

How can I use Querydsl to replace?

1 Answer 1

1

Let's assume you are using Querydsl SQL and you have generated your metamodel for Querydsl. Then you could describe the given query as

QMonitorInfo monitorInfo = QMonitorInfo.monitorInfo;
List<Tuple> result = query.from(monitorInfo)
      .where(
         monitorInfo.dsid.eq(9211),
         monitorInfo.time.between(start, end))
      .list(monitorInfo.value.castToNum(Integer.class).max(), 
            monitorInfo.value.castToNum(Integer.class).min());
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. But your information is similer to List<Tuple> result = query.from(monitorInfo).where(monitorInfo.dsid.eq(9211)).where(monitorInfo.time.between(start, end)).uniqueResult(monitorInfo.value.castToNum(Integer.class).max(),monitorInfo.value.castToNum(Integer.class).min()); with two method ,I get the return data is null. why I use nest SQL ? because monitorInfo.value isn't number ,it's varchar.
Are you using Querydsl with JPA or SQL? Do you get null or an empty list or a list with null as the only entry?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.