我想在我的选择查询中隐藏一列,发现跳过列名称可以做到这一点,但是正确的语法是什么?

这是我的代码

select t1.location, MAX(DATE_ADD((FROM_UNIXTIME(t2.t_stamp/1000)),INTERVAL 4 HOUR) AS Tstamp,

  max(case when t2.locationid = '2847' then t2.value end) MR,
  max(case when t2.locationid = '2839' then t2.value end) Flow,
  max(case when t2.locationid = '2834' then t2.value end) Pressure,
  max(case when t2.locationid = '2836' then t2.value end) Level

from table2 t2
inner join table1 t1
  on t1.id = '2847'
group by t1.location


所以在输出中,我的列具有最新值,

Location |        Tstamp        | MR | Flow | Pressure | Level
   East  |  2013-11-10 12:00 PM | 10 |  20  |   30     |   40


四小时前

Location |        Tstamp        | MR | Flow | Pressure | Level
   East  |  2013-11-10 08:00 AM | 20 |  25  |   34     |   45


而我想发生的事情就是:

Location | MR | Flow | Pressure | Level
   East  | 20 |  25  |   34     |   45


如果我从选择查询中删除了t_stamp,我怎么仍能在四个小时前显示这些值?

最佳答案

select t1.location,
  max(case when t2.locationid = '2847' then t2.value end) MR,
  max(case when t2.locationid = '2839' then t2.value end) Flow,
  max(case when t2.locationid = '2834' then t2.value end) Pressure,
  max(case when t2.locationid = '2836' then t2.value end) Level
from table2 t2
inner join table1 t1 on t1.id = '2847'
where now() - INTERVAL 4 HOUR >= FROM_UNIXTIME(t2.t_stamp/1000)
group by t1.location

关于mysql - 如何在MySQL中的选择查询中使用跳过列名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20008720/

10-12 06:44