1. 程式人生 > 其它 >在 某專案下 某個時間段內 查詢某型別感測器下 各個感測器 所有原始資料的最大值最小值

在 某專案下 某個時間段內 查詢某型別感測器下 各個感測器 所有原始資料的最大值最小值

技術標籤:Java軟體開發sqlmysql

在 某專案下 某個時間段內 查詢某型別感測器下 各個感測器 所有原始資料的最大值最小值

sensor表(感測器表)

sensor_data表(感測器資料表)

SELECT
	id,
	max( Vx ) AS maxVx,
	max( Vy ) AS maxVy,
	max( Vz ) AS maxVz,
	min( Vx ) AS minVx,
	min( Vy ) AS minVy,
	min( Vz ) AS minVz 
FROM
	pkg,
	sensor 
WHERE
	id IN ( SELECT sensorId FROM `sensor` WHERE sensorTypeEng = 'temperature' AND projectId = '1607916999916' ) 
	AND pkg.update_time BETWEEN '2019-12-14 02:53:56' 
	AND '2021-12-14 02:53:56' 
GROUP BY
	id

子查詢(wherein +子查詢語句)

SELECT sensorId FROM `sensor` WHERE sensorTypeEng='temperature' and projectId='1607916999916'

執行全部SQL語句

SELECT
	id,
	max( Vx ) AS maxVx,
	max( Vy ) AS maxVy,
	max( Vz ) AS maxVz,
	min( Vx ) AS minVx,
	min( Vy ) AS minVy,
	min( Vz ) AS minVz 
FROM
	pkg,
	sensor 
WHERE
	id IN ( SELECT sensorId FROM `sensor` WHERE sensorTypeEng = 'temperature' AND projectId = '1607916999916' ) 
	AND pkg.update_time BETWEEN '2019-12-14 02:53:56' 
	AND '2021-12-14 02:53:56' 
GROUP BY
	id