MySQL左联接,联接表具有别名

时间:2019-12-28 02:23:12

标签: mysql sql left-join alias

我有5张桌子:

  1. 日期时间(ID,日期时间)
  2. 具有(ID,ID_ESP,值,id_date_time)的温度
  3. 湿度(ID,ID_ESP,值,id_date_time)
  4. 带有(ID,ID_ESP,值,id_date_time)的压力
  5. 带有(ID,位置,名称,sensor_config)的esp_list

值(温度,按和嗡嗡声)来自ESP32,并且将以相同的时间值插入到2,3和4中。

我想显示按日期排序的值,仅播出1.date_time,2.value作为温度,3.value作为湿度,4.value作为压力和5.name,而不显示5.location和5.sensor_config 到此为止,但是如何在左边的联接表上使用别名?

这是我使用的查询:

SELECT * FROM date_time as t
left join temperature as temp on t.ID = temp.id_date_time
left JOIN humidity as hum on t.ID = hum.id_date_time
left join pressure as press on t.ID = press.id_date_time
left join esp_list as esp on temp.ID_ESP = esp.ID
where hum.ID_ESP = 1 AND temp.ID_ESP = 1 AND press.ID_ESP = 1
order by t.date_time DESC

到目前为止,这是我的收获:

enter image description here

1 个答案:

答案 0 :(得分:0)

SELECT *更改为

SELECT t.date_time, temp.value AS temperature, hum.value AS humidity, press.value AS pressure, esp.name