因为数据是按照每天一张表存放的 所以多天查询的时候 就需要表关联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) t2group by a,b,d这个SQL 如果只查当天的数据是正常的 如果查询1天以上就会出现问题 就第一天的数据是正常的 后面的数据 不正常