SQL 嵌套查询
查询电参数表 平均电压 最大电流 最大有功无功功率 最大有功无功功率产生时间等
SELECT AVG(Uab) as Uab_avg , AVG(Ubc) as Ubc_avg , AVG(Uca) as Uca_avg,MAX(Ia) as Ia_max,MAX(Ic) as Ic_max ,
Max(P) as P_max,(Select Top 1 data from 电参数表_204_1 where P = (Select MAX(P) from 电参数表_204_1))as data_pmax ,
Max(Q) as Q_max,(Select Top 1 data from 电参数表_204_1 where Q = (Select MAX(Q) from 电参数表_204_1)) as data_qmax,
MAX(COS) as cos_max,AVG(Temp0) as Temp0_avg,
(case when (Select Top 1 E_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 1 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') is null then 0 else (Select Top 1 E_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 1 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') end) as E_DL,
(case when (Select Top 1 Q_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 1 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') is null then 0 else (Select Top 1 E_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 1 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') end) as Q_DL
FROM 电参数表_204_1 where data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999'
union all
SELECT AVG(Uab) as Uab_avg , AVG(Ubc) as Ubc_avg , AVG(Uca) as Uca_avg,MAX(Ia) as Ia_max,MAX(Ic) as Ic_max ,
Max(P) as P_max,(Select Top 1 data from 电参数表_204_2 where P = (Select MAX(P) from 电参数表_204_2))as data_pmax ,
Max(Q) as Q_max,(Select Top 1 data from 电参数表_204_2 where Q = (Select MAX(Q) from 电参数表_204_2)) as data_qmax,
MAX(COS) as cos_max,AVG(Temp0) as Temp0_avg,
(case when (Select Top 1 E_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 2 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') is null then 0 else (Select Top 1 E_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 2 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') end) as E_DL,
(case when (Select Top 1 Q_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 2 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') is null then 0 else (Select Top 1 E_DL from 电量日报表 where FZaddr = 204 and NODEaddr = 2 and data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999') end) as Q_DL
FROM 电参数表_204_2 where data between '2013-10-19 00:00:00.000' and '2013-10-19 23:59:59.999'
浙公网安备 33010602011771号