MyBatis select查询是否可以读取Select和Group By命令的变量值?如果可能的话,我应该如何将aggregationKeys
变量放在那个位置? (查看代码):
@Select({"SELECT #{aggregationKeys}, SUM(value) " +
"FROM usage_counter WHERE " + /*zrobic mape i pociagnac to tak, ze: (#{zmyslona wartosc} IS NULL OR api_consumer) itd*/
"(#{apiConsumerIds} IS NULL OR #{apiConsumerIds} like '%,'||api_consumer||',%' ) AND " +
"(#{serviceIds} IS NULL OR #{serviceIds} like '%,'||service||',%' ) AND " +
"(#{rateplanIds} IS NULL OR #{rateplanIds} like '%,'||rateplan||',%' ) AND " +
"(#{dateFrom} IS NULL OR date >= #{dateFrom} ) AND " +
"(#{dateTo} IS NULL OR date <= #{dateTo} ) AND " +
"(#{statuses} IS NULL OR #{statuses} like '%,'||counter_status||',%' ) " +
"GROUP BY ||#{aggregationKeys}||"})
@Results({
@Result(property = "date", column = "date"),
@Result(property = "apiConsumerId", column = "api_consumer"),
@Result(property = "serviceId", column = "service"),
@Result(property = "value", column = "value")
})
List<AggregatedUsage> getAggregatedUsageCounters(@Param("aggregationKeys") String aggregationKeys, @Param("dateFrom") Date dateFrom, @Param("dateTo") Date dateTo, @Param("apiConsumerIds") String apiConsumerIds, @Param("serviceIds") String serviceIds, @Param("statuses") String statuses);
编辑:或者是否可以通过两个或多个值在Java流中进行分组(在这种情况下最多4个)?
第二次编辑: - 确定它是可能的,但是它使得流非常复杂,我觉得无效。