[size=medium][color=blue] select t1.m,t1.pid ,max(t1.rel_energy) - min(t1.rel_energy) aa
from (
(select substring(t.cur_date from 1 for 10) as m,t.rel_energy,t.pid
from t_electric_detail_copy t) ) t1
group by t1.m,t1.pid order by pid[/color][/size]
from (
(select substring(t.cur_date from 1 for 10) as m,t.rel_energy,t.pid
from t_electric_detail_copy t) ) t1
group by t1.m,t1.pid order by pid[/color][/size]