我有一个带
的TABLEID,MasterID,beerline,temperature,temperaturetime,receivedtime
这是一张从某些硬件获取ID的表格,其中包含啤酒花编号和温度读数。
我试图从具有独特masterID和beerline的这些线路获得MAX - MIN - CURRENT温度读数
SELECT
MasterID,beerline, MAX(temperature) as max, MIN(temperature) as min, temperature
FROM `temperatures`
WHERE temperatures.MasterID IN
(SELECT masterdata.masterNo FROM masterdata WHERE masterdata.customerNo = '$customerID')
GROUP BY temperatures.beerline, temperatures.MasterID
ORDER BY `receivedtime` DESC
这根本没有给我正确的价值,但是我不能理解我应该尝试的其他东西。
示例数据:
MasterID beerline temperature temperaturetime receivedtime
- 5049 13 23 2017-10-24 13:24:00 2017-10-24 13:24:01
- 5049 14 25 2017-10-24 13:24:00 2017-10-24 13:24:01
- 4006 13 22 2017-10-24 13:22:55 2017-10-24 13:22:56
- 4006 14 -1 2017-10-24 13:22:55 2017-10-24 13:22:56
- 5049 13 23 2017-10-24 13:21:59 2017-10-24 13:22:01
- 5049 14 23 2017-10-24 13:21:59 2017-10-24 13:22:01
- 4006 13 22 2017-10-24 13:20:54 2017-10-24 13:20:56
- 4006 14 0 2017-10-24 13:20:54 2017-10-24 13:20:56
- 5049 13 20 2017-10-24 13:19:59 2017-10-24 13:20:00
- 5049 14 23 2017-10-24 13:19:59 2017-10-24 13:20:00
- 4006 14 0 2017-10-24 13:18:54 2017-10-24 13:18:55
- 4006 13 22 2017-10-24 13:18:54 2017-10-24 13:18:55
我想要的是什么:
MasterID beerline temperature MAX(temperature) MIN(Temperature)
- 4006 13 22 22 22
- 4006 14 -1 0 -1
- 5049 13 23 23 20
- 5049 14 25 25 23
这是我的sqlfiddle: