0

我目前有以下查询:

select min(nw_lpdTEMP) AS Min_Lkpmp_Temp_C,
  max(nw_lpdPH) AS Max_Lkpmp_PH,
(select format(nw_uvttlflw,7) from tag_history 
  where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60)
  Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59' order by nw_bpdcl2 limit 1) as Min_GPM, 
  format(min(nw_bpdcl2),7) as Min_Chlorine_Residual,
(select format(nw_uvttlflw,7) from tag_history
  where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60)
  Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59' order by nw_bpdcl2 desc limit 1) as Max_GPM,
  format(max(nw_bpdcl2),7) as Max_Chlorine_Residual from tag_history 
  where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60) 
  Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59'

我想看看我是否可以添加以下查询,它返回 24 小时之间每分钟一加仑流量​​ (nw_uvttlflw) 的总和。我可以运行自己尝试添加到上述查询的(总和查询)查询,它会返回我想要的内容。我当前的问题是尝试将其与上述查询嵌套,因此它将总和(nw_uvttlflw)作为原始较大查询中的最后一列返回。(对不起,我对嵌套 SQL 查询缺乏高质量的格式,因为我不是最精通冗长的查询)

我要附加的查询在这里:

select format(sum(nw_uvttlflw),7) as Total_flow from tag_history
where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60) 
Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59';

非常感谢您的时间和精力。一段时间以来,我一直试图将其拼凑在一起,但无法使我的语法正确。谢谢

-标记

4

1 回答 1

0

这是你要找的吗?

select min(nw_lpdTEMP) AS Min_Lkpmp_Temp_C,
  max(nw_lpdPH) AS Max_Lkpmp_PH,
  (select format(nw_uvttlflw,7) from tag_history 
    where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60)
    Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59' order by nw_bpdcl2 limit 1) as Min_GPM, 
  format(min(nw_bpdcl2),7) as Min_Chlorine_Residual,
  (select format(nw_uvttlflw,7) from tag_history
    where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60)
    Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59' order by nw_bpdcl2 desc limit 1) as Max_GPM,
  format(max(nw_bpdcl2),7) as Max_Chlorine_Residual,
  (select format(sum(nw_uvttlflw),7) from tag_history
    where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60) 
    Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59') as Total_flow
from tag_history 
where from_unixtime(floor(unix_timestamp(t_stamp)/60)*60) 
  Between '2012-07-01 00:00:00' AND '2012-07-01 23:59:59'
于 2012-08-16T19:03:24.963 回答