mybatis mapper把传递来的参数当作字段写入结果集中

mybatis mapper把传递来的参数当作字段写入结果集中_第1张图片 mybatis mapper把传递来的参数当作字段写入结果集中_第2张图片


   
   
   
   
                    column="{StationStatsId=stationStatsId,EndTime=EndTime,StartTime=StartTime}" ofType="com.extracme.evshare.business.entity.EquipmentStatsInfo">
    

   
 


-------------mapper把传递来的参数当作字段写入结果集中----------


 

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

你可能感兴趣的:(mybits)