select a,b,d,min(c) as minc,max(c) as maxc, DATEDIFF(mi,min(c),max(c))+1 as 时长 from ( select a,b,c,row_number() over (partition by a order by c)-row_number() over (partition by a,b order by c) as d from ( select id a,case when cast (value as float)>=20 then '运行' else '停机' end as b,acptime c from ${REPLACE(SQL("JDBC5","select name from sysobjects where xtype='u' and name like 'ValueTable_FLOAT_%' and REPLACE(name,'ValueTable_FLOAT_','')>='"+FORMAT(KSRQ,"yyyy_MM_dd")+"' and REPLACE(name,'ValueTable_FLOAT_','')<='"+FORMAT(JSRQ,"yyyy_MM_dd")+"'",1),","," where 1=1 "+IF(LEN(ID)==0,""," and ID IN ('"+ID+"')")+" union all select ID,Value,AcpTime from ")} where 1=1 ${IF(LEN(ID)==0,""," and ID IN ('"+ID+"')")} ) t1 ) t2 group by a,b,d
这样只有 第一天的数据正确 |