mybatis mapper把传递来的参数当作字段写入结果集中
来源:互联网 发布:java apache 框架 编辑:程序博客网 时间:2024/05/18 04:15
<resultMap id="StatsResultMap" type="com.extracme.evshare.business.entity.StationStatsInfo" >
<result column="Station_Id" jdbcType="VARCHAR" property="StationID" />
<result column="Station_Electricity" jdbcType="DOUBLE" property="StationElectricity" />
<result column="StartTime" property="StartTime" />
<result column="EndTime" property="EndTime" />
<collection property="EquipmentStatsInfos" javaType="ArrayList" select="com.extracme.evshare.business.tserver.mapper.EquipmentStatsMapper.queryEquipmentStatsInfoByStatsId"
column="{StationStatsId=stationStatsId,EndTime=EndTime,StartTime=StartTime}" ofType="com.extracme.evshare.business.entity.EquipmentStatsInfo">
</collection>
</resultMap>
-------------mapper把传递来的参数当作字段写入结果集中----------
<select id="queryStationStats" parameterType="java.util.Map" resultMap="StatsResultMap">
select
# {startTime,jdbcType=VARCHAR} as StartTime,
# {endTime,jdbcType=VARCHAR} as EndTime,
Station_Stats_Id stationStatsId ,
Station_Id
from station_stats
where 1=1
<if test="stationId != null and stationId !='' " >
and Station_Id = #{stationId,jdbcType=VARCHAR}
</if>
<if test="startTime != null and startTime !='' ">
and UNIX_TIMESTAMP(Start_Time) >= UNIX_TIMESTAMP(#{startTime,jdbcType=VARCHAR})
</if>
<if test="endTime != null and endTime !='' ">
and UNIX_TIMESTAMP(End_Time) <= UNIX_TIMESTAMP(#{endTime,jdbcType=CARCHAR})
</if>
<!-- GROUP BY stationStatsId WITH ROLLUP -->
</select>
ps:求站的总电量,站下各个设备的总量以及设备下各个接口的总量;一个站在每天会insert一条记录:时间段内query如下
SELECT
s.Station_Stats_Id,
c.Connector_Stats_Id,e.Equipment_Stats_Id,
s.Station_Id,s.Station_Electricity,
e.Equipment_Id,e.Equipment_Electricity,
c.Connector_Id,c.Connector_Electricity
FROM
station_stats s
inner JOIN equipment_stats e ON s.Station_Stats_Id = e.Station_Stats_Id
inner JOIN connector_stats c ON e.Equipment_Stats_Id = c.Equipment_Stats_Id
where s.Station_Id=720 #and s.Start_Time>'2017-07-15 00:00:00' and s.End_Time<'2017-07-18 00:00:00'
AND UNIX_TIMESTAMP(s.Start_Time) >= UNIX_TIMESTAMP('2017-07-15')
AND UNIX_TIMESTAMP(s.End_Time) <= UNIX_TIMESTAMP('2017-07-18')
GROUP BY s.Station_Stats_Id,s.Station_Id,e.Equipment_Id,c.Connector_Id
最终优化之后数据结构:
SELECT
s.Station_Id,
#s.Station_Electricity,
e.Equipment_Id,
#e.Equipment_Electricity,
c.Connector_Id,
SUM(s.Station_Electricity) Station_Electricity,
SUM(e.Equipment_Electricity) Equipment_Electricity,
SUM(c.Connector_Electricity) Connector_Electricity
FROM
station_stats s
inner JOIN equipment_stats e ON s.Station_Stats_Id = e.Station_Stats_Id
inner JOIN connector_stats c ON e.Equipment_Stats_Id = c.Equipment_Stats_Id
where s.Station_Id=720 #and s.Start_Time>'2017-07-15 00:00:00' and s.End_Time<'2017-07-18 00:00:00'
AND UNIX_TIMESTAMP(s.Start_Time) > UNIX_TIMESTAMP('2017-07-15')
AND UNIX_TIMESTAMP(s.End_Time) < UNIX_TIMESTAMP('2017-07-18')
GROUP BY s.Station_Id,e.Equipment_Id,c.Connector_Id
- mybatis mapper把传递来的参数当作字段写入结果集中
- 把mybatis做统计的字段结果取出来 DATEDIFF
- Jquery把整个表单当作参数传递
- SQL 把查询结果当作"表"来使用
- 如何把个表的合计字段 合并SQL查询到一个结果集中
- MyBatis查询返回Map时设置值为null的字段也在结果集中
- 删除结果集中字段重复的方法
- mybatis的mapper返回map结果集
- mybatis的mapper返回map结果集
- mybatis直接执行前台传递的sql语句(mapper参数即为sql字符串)
- 怎样把ACE_Task当作更高级的线程来使用
- 把break 当作goto 的一种形式来用
- Spring boot + MyBatis 查询返回Map时设置值为null的字段也在结果集中
- Mybatis的使用mapper传多个参数
- 更新查询的结果集中的某个字段
- mybatis mapper参数解析
- dorado单独给结果集中的字段赋值
- 把人生当作程序来设计
- bzoj 3597: [Scoi2014]方伯伯运椰子 spfa判负环+分数规划
- 搭建本地服务器的方法:
- SpringCloud学习笔记之Feign结合Hystrix实现服务容错保护
- 几种将存储为str的其他类型转换回去的方法
- C#191课的主要内容
- mybatis mapper把传递来的参数当作字段写入结果集中
- Android代码混淆之混淆规则
- AI:IPPR的模式生成-学习/训练方式(基本结构)
- c++实现顺序查找,折半查找
- 插入排序
- ES中查询数据使用date_histogram时报错
- Java集合知识点总结
- ubuntu/var/log/下各个日志文件
- Python基础入门教程,Python学习路线图