如何在mysql的select查询中使用skip列名

时间:2013-11-15 19:08:08

标签: mysql hide

我想在我的select查询中隐藏其中一列,并发现跳过列名称可以执行此操作,但是正确的语法是什么?

这是我的代码

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,我怎样才能在四小时前显示这些值?

1 个答案:

答案 0 :(得分:1)

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