
---
#领域/物联实验室 

#复盘/0 #临时/备忘

## 一句话描述

[___Dataease 配置数据集_____]

---
### 今日人流量
```mysql
SELECT 
  -- 给重名字段起别名，避免查询结果字段冲突
--   c1.InNum AS c1_InNum,
--   c1.OutNum AS c1_OutNum,
--   c2.InNum AS c2_InNum,
--   c2.OutNum AS c2_OutNum,
  
  c1.InNum + c2.InNum as innum,
  c1.OutNum + c2.OutNum as outnum
FROM 
  (SELECT InNum, OutNum FROM people WHERE deviceid = 'AG00897PAGF39E1' ORDER BY DataDateTime desc limit 1) AS c1
LEFT JOIN 
  (SELECT InNum, OutNum FROM people WHERE deviceid = 'AG00897PAG81E9C' ORDER BY DataDateTime desc limit 1) AS c2
-- 核心修复：添加LEFT JOIN连接条件（根据业务逻辑选择）
ON 1= 1;
```

### 本周人流量
```mysql
SELECT 
  ROUnD(SUM(InNum + OutNum) / 1.5) AS 本周总人流量
FROM (
  -- 每个设备只取 1 条最新记录（累计值不会重复）
  SELECT deviceId, MAX(InNum) AS InNum, MAX(OutNum) AS OutNum
  FROM people
  WHERE YEARWEEK(DataDateTime, 1) = YEARWEEK(NOW(), 1)
  GROUP BY deviceId
) AS t;
```

### 环境平均
```mysql
SELECT
  DATE_FORMAT(Time, '%y/%m/%d') AS month_day,
  AVG(Temperature) AS Temperature,
	AVG(Humidity) AS Humidity,
	AVG(TVOC) AS TVOC,
	AVG(eCO2) AS eCO2,
	AVG(PM10) AS PM10,
	AVG(PM2_5) AS PM2_5
FROM
  env
GROUP BY
  month_day 
ORDER BY
  month_day desc limit 30;
```

### 环境
```mysql
select * from env order by id desc limit 1;
```

### 行为数据
```mysql
SELECT * from (
select * from (SELECT
	DataDateTime,
	"人流经过" AS 行为
FROM
	people
WHERE
	 type = '1' order by DataDateTime desc) as t1
	UNION ALL
	select * from (SELECT `datetime`, `msg` from log where `msg`!='物联控制' and `msg`!="") as t2
) as t1_2 ORDER BY DataDateTime desc limit 20;
```
