找出每笔贷款有多少天? 查找平均UPB最高的州。 每笔贷款的期限为30年。检索贷款编号,律师姓名和预计的贷款完成日期。
public class MyProcessingTimeTrigger extends Trigger<Object, TimeWindow> {
// a state which keeps a session start.
private final ValueStateDescriptor<Long> stateDescriptor = new ValueStateDescriptor<Long>("session-start", Long.class);
@Override
public TriggerResult onElement(Object element, long timestamp, TimeWindow window, TriggerContext ctx) throws Exception {
ValueState<Long> state = ctx.getPartitionedState(stateDescriptor);
if(state.value() == null) {
// if value is null, it's a session start.
state.update(window.getStart());
}
ctx.registerProcessingTimeTimer(window.maxTimestamp());
return TriggerResult.CONTINUE;
}
@Override
public TriggerResult onProcessingTime(long time, TimeWindow window, TriggerContext ctx) {
// here is a session end.
return TriggerResult.FIRE;
}
@Override
public void clear(TimeWindow window, TriggerContext ctx) throws Exception {
ctx.getPartitionedState(stateDescriptor).clear();
ctx.deleteProcessingTimeTimer(window.maxTimestamp());
}
}
答案 0 :(得分:1)
您不能混用MAX(AVG(UPB))
之类的聚合。
使用这个:
SELECT STATE, AVG(UPB)
FROM LOAN
GROUP BY STATE
HAVING AVG(UPB) = (
SELECT TOP (1) AVG(UPB)
FROM LOAN
GROUP BY STATE
ORDER BY AVG(UPB) DESC
)
对于第一个查询,以天为单位进行计算:
SELECT DATEDIFF(day, LoanDate, GETDATE()) as daysold