,EXTRACT(MONTH FROM cur_time)
,EXTRACT(MONTH FROM cur_time),EXTRACT(DAY FROM cur_time)
,EXTRACT(MONTH FROM cur_time),EXTRACT(DAY FROM cur_time),EXTRACT(HOUR FROM cur_time)
,EXTRACT(MONTH FROM cur_time) as monthStr
,EXTRACT(MONTH FROM cur_time) as monthStr,EXTRACT(DAY FROM cur_time) as dayStr
,EXTRACT(MONTH FROM cur_time) as monthStr,EXTRACT(DAY FROM cur_time) as dayStr,EXTRACT(HOUR FROM cur_time) as hourStr
,EXTRACT(MONTH FROM cur_time)
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 day')), EXTRACT(DAY FROM (cur_time + INTERVAL '1 day'))
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 hour')), EXTRACT(DAY FROM (cur_time + INTERVAL '1 hour')), EXTRACT(HOUR FROM (cur_time + INTERVAL '1 hour'))
,EXTRACT(MONTH FROM cur_time) as monthStr
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 day')) as monthStr,EXTRACT(DAY FROM (cur_time + INTERVAL '1 day')) as dayStr
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 hour')) as monthStr,EXTRACT(DAY FROM (cur_time + INTERVAL '1 hour')) as dayStr,EXTRACT(HOUR FROM (cur_time + INTERVAL '1 hour')) as hourStr
and a.monthStr = b.monthStr
and a.monthStr = b.monthStr and a.dayStr = b.dayStr
and a.monthStr = b.monthStr and a.dayStr = b.dayStr and a.hourStr = b.hourStr
order by timeStr
SELECT
b.timeStr,
b.deviceType,
b.sumValue AS curValue,
a.sumValue AS lastValue,
CASE
WHEN a.sumValue > 0 THEN CONCAT(CAST((b.sumValue - a.sumValue) / a.sumValue * 100 AS NUMERIC(18, 2)), '%')
ELSE '同期无数据'
END AS yoy
FROM (
SELECT
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
SUM(calc_value) AS sumValue,
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
FROM ${lastTableName} dh
WHERE cur_time >= #{yoyStartTime}::timestamp
AND cur_time <= #{yoyEndTime}::timestamp
AND calc_value IS NOT NULL
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
UNION ALL
SELECT
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
SUM(calc_value) AS sumValue,
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
FROM ${curTableName} dh
WHERE cur_time >= #{startTime}::timestamp
AND cur_time <= #{endTime}::timestamp
AND calc_value IS NOT NULL
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
) a RIGHT JOIN (
SELECT
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
SUM(calc_value) AS sumValue,
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
FROM ${lastTableName} dh
WHERE cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp
AND calc_value IS NOT NULL
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
UNION ALL
SELECT
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
SUM(calc_value) AS sumValue,
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
FROM ${curTableName} dh
WHERE cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp
AND calc_value IS NOT NULL
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
) b ON (a.yearStr::integer + 1) = b.yearStr
SELECT
b.timeStr,
b.deviceType,
b.sumValue AS curValue,
a.sumValue AS lastValue,
CASE
WHEN a.sumValue > 0
THEN CONCAT( ( (b.sumValue - a.sumValue) / a.sumValue * 100 )::NUMERIC(18,2), '%' )
ELSE '同期无数据'
END AS yoy
FROM (
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
FROM ${yoyLastTableName} dh
WHERE
cur_time >= #{yoyStartTime}::timestamp AND cur_time <= #{yoyEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
UNION ALL
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
FROM ${yoyCurTableName} dh
WHERE
cur_time >= #{yoyStartTime}::timestamp AND cur_time <= #{yoyEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
) a
RIGHT JOIN (
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
FROM ${lastTableName} dh
WHERE
cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
UNION ALL
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
FROM ${curTableName} dh
WHERE
cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
) b ON a.yearStr + 1 = b.yearStr
SELECT
t1.timeStr,
t1.sumValue AS curValue,
t2.sumValue AS lastValue,
CASE
WHEN t2.sumValue > 0 THEN CONCAT(CAST((t1.sumValue - t2.sumValue) / t2.sumValue * 100 AS NUMERIC(18, 2)), '%')
ELSE '上期无数据'
END AS mom
FROM (
SELECT
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
SUM(calc_value) AS sumValue,
EXTRACT(YEAR FROM cur_time) AS yearStr
,EXTRACT(MONTH FROM cur_time) AS monthStr
FROM ${tableName} dh
WHERE cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp
AND calc_value IS NOT NULL
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
,EXTRACT(MONTH FROM cur_time)
) t1
LEFT JOIN (
SELECT
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
SUM(calc_value) AS sumValue,
EXTRACT(YEAR FROM cur_time) AS yearStr
,EXTRACT(MONTH FROM cur_time) AS monthStr
FROM ${tableName} dh
WHERE cur_time >= #{momStartTime}::timestamp AND cur_time <= #{momEndTime}::timestamp
AND calc_value IS NOT NULL
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY EXTRACT(YEAR FROM cur_time)
,EXTRACT(MONTH FROM cur_time)
) t2 ON
t1.monthStr = t2.monthStr + 1
t1.yearStr = t2.yearStr + 1
ORDER BY timeStr
select
t1.timeStr,
t1.sumValue as curValue,
t2.sumValue as lastValue,
case
when t2.sumValue > 0 then concat(to_char( ((t1.sumValue - t2.sumValue)/t2.sumValue*100), 'FM999999999990.00'), '%')
else '上期无数据'
end as mom
from
(
select
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}) as timeStr,
cast(coalesce(avg(case when calc_value != 0 then calc_value else null end),0)*1.0 as numeric(15,2)) as sumValue,
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
from
${tableName} dh
where
cur_time >= #{startTime}::timestamp
and cur_time <= #{endTime}::timestamp
and calc_value is not null
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}),
extract(year from cur_time)
) t1
left join
(
select
cast(coalesce(avg(case when calc_value != 0 then calc_value else null end),0)*1.0 as numeric(15,2)) as sumValue,
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
from
${tableName} dh
where
cur_time >= #{momStartTime}::timestamp
and cur_time <= #{momEndTime}::timestamp
and calc_value is not null
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
extract(year from cur_time)
) t2 on
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr and t1.hourStr = t2.hourStr
order by timeStr
select
t1.timeStr,
t1.sumValue as curValue,
t2.sumValue as lastValue,
case
when t2.sumValue > 0 then concat(to_char( ((t1.sumValue - t2.sumValue)/t2.sumValue*100), 'FM999999999990.00'), '%')
else '上期无数据'
end as mom
from
(
select
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}) as timeStr,
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
from
${tableName1} dh
where
cur_time >= #{startTime}::timestamp
and cur_time <= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}),
extract(year from cur_time)
union all
select
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}) as timeStr,
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
from
${tableName2} dh
where
cur_time >= #{startTime}::timestamp
and cur_time <= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}),
extract(year from cur_time)
) t1
left join
(
select
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
from
${tableName1} dh
where
cur_time >= #{momStartTime}::timestamp
and cur_time <= #{momEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
extract(year from cur_time)
union all
select
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
from
${tableName2} dh
where
cur_time >= #{momStartTime}::timestamp
and cur_time <= #{momEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
and dl.device_type = #{paramType}
and cpm.system_type = #{systemType}
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
extract(year from cur_time)
) t2 on
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr and t1.hourStr = t2.hourStr
order by timeStr
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
'YYYY'
'YYYY-MM'
'YYYY-MM-DD'
'YYYY-MM-DD HH24'
'YYYY-MM-DD HH24:MI'
'YYYY-MM-DD HH24:MI:SS'
) as timeStr
from
${curTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
TO_CHAR(dm.cur_time,
'YYYY'
'YYYY-MM'
'YYYY-MM-DD'
'YYYY-MM-DD HH24'
'YYYY-MM-DD HH24:MI'
'YYYY-MM-DD HH24:MI:SS'
order by timeStr
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
'YYYY'
'YYYY-MM'
'YYYY-MM-DD'
'YYYY-MM-DD HH24'
'YYYY-MM-DD HH24:MI'
'YYYY-MM-DD HH24:MI:SS'
) as timeStr
from
${lastTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
and cpm.system_type = #{systemType}
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
TO_CHAR(dm.cur_time,
'YYYY'
'YYYY-MM'
'YYYY-MM-DD'
'YYYY-MM-DD HH24'
'YYYY-MM-DD HH24:MI'
'YYYY-MM-DD HH24:MI:SS'
)
union all
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
'YYYY'
'YYYY-MM'
'YYYY-MM-DD'
'YYYY-MM-DD HH24'
'YYYY-MM-DD HH24:MI'
'YYYY-MM-DD HH24:MI:SS'
) as timeStr
from
${curTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
and cpm.system_type = #{systemType}
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
TO_CHAR(dm.cur_time,
'YYYY'
'YYYY-MM'
'YYYY-MM-DD'
'YYYY-MM-DD HH24'
'YYYY-MM-DD HH24:MI'
'YYYY-MM-DD HH24:MI:SS'
)
order by timeStr
select
sum(coalesce(calc_value,0)) as curValue,
'efrMeter' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '5'
and cpm.grade = 140
and cpm.terminal_device_type = '15'
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrCloud' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '6'
and cpm.grade = 140
and cpm.terminal_device_type = '15'
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
select
sum(coalesce(calc_value,0)) as curValue,
'efrMeter' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${lastTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '5'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrCloud' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${lastTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '6'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrMeter' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '5'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrCloud' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '6'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
dm.cur_time as timeStr
from
${lastTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
and cpm.system_type = #{systemType}
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
dm.cur_time
union all
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
dm.cur_time as timeStr
from
${curTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time <= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
and cpm.system_type = #{systemType}
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
dm.cur_time
order by timeStr