最近,我写了一个连接数据库的程序!
我认为将sql替换为querydsl;
例如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'
)
)
如何使用Querydsl替换?
答案 0 :(得分:1)
假设您使用的是Querydsl SQL并且已经为Querydsl生成了元模型。然后,您可以将给定的查询描述为
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());