测试:
select
avg(WEIGHT),TEST_DATE
from
data_weight
where
`SOURCE`='108'
and date_format(test_date,'%Y%m%d')>='20160926'
and date_format(test_date,'%Y%m%d')<='20160927'
and `USERID`='CFA2FC3C8E784CCCB5E5DB5F708FD859'
group by
date_format(test_date,'%Y%m%d')
ORDER BY
test_date
后台需要转码
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
String startTime1 = sdf.format(startTime);
String endTime1 = sdf.format(endTime);
mybatis中的内容:
select
avg(moisture) moisture,
avg(ADIPOSE_RATE) ADIPOSE_RATE,
avg(BONE_MASS) BONE_MASS,
avg(VISCERAL_FAT) VISCERAL_FAT,
TEST_DATE
from
data_bodycomposition
where
`SOURCE`=#{source}
and date_format(test_date,'%Y%m%d')>=#{startTime}
and date_format(test_date,'%Y%m%d')<=#{endTime}
and `USERID`=#{userId}
group by
date_format(test_date,'%Y%m%d')
ORDER BY
TEST_DATE
desc
另外还附上本人处理float类型的方法, 容易忘记
float a = 123.2334f;
float b = (float)(Math.round(a*100))/100;(这里的100就是2位小数点,如果要其它位,如4位,这里两个100改成10000)
本文介绍了一种使用 MyBatis 进行复杂 SQL 查询的方法,特别是涉及平均值计算的分组查询,并提供了针对特定日期范围的数据筛选技巧。此外,还分享了一个简单有效处理浮点数精度问题的 Java 示例。
1351

被折叠的 条评论
为什么被折叠?



