# 大屏核心KPI统计 (总设备数、运行数、告警数) SELECT COUNT(*) as total_devices, SUM(CASE WHEN status='running' THEN 1 ELSE 0 END) as running_devices, SUM(CASE WHEN status='alarm' THEN 1 ELSE 0 END) as alarm_devices FROM equipment_status; # 特定区域设备状态查询 SELECT device_id, location, status, motor_current, chain_speed FROM equipment_status WHERE region = '华北矿区' AND ts >= now - 1m; # 最新告警信息滚动 SELECT device_id, alarm_level, alarm_message, ts FROM equipment_alarms WHERE ts >= now - 24h ORDER BY ts DESC LIMIT 10;
# 基础历史数据查询 SELECT ts, motor_current, temperature, vibration, chain_speed FROM equipment_status WHERE device_id = 'BNC-2024001' AND ts >= '2024-10-01 00:00:00' AND ts <= '2024-10-21 23:59:59' ORDER BY ts ASC; # 异常数据快速定位 SELECT ts, motor_current, temperature, vibration FROM equipment_status WHERE device_id = 'BNC-2024001' AND ts >= '2024-10-15 00:00:00' AND (temperature > 85 OR vibration > 7.5) ORDER BY ts DESC; # 时间窗口聚合分析 SELECT _wstart as window_start, AVG(temperature) as avg_temp, MAX(vibration) as max_vib, COUNT(*) as data_points FROM equipment_status WHERE device_id = 'BNC-2024001' AND ts >= '2024-10-15 00:00:00' AND ts <= '2024-10-16 23:59:59' INTERVAL(10m); # 指标关联分析 SELECT ts, motor_current, temperature, vibration, (motor_current * 0.8 + temperature * 0.2) as health_score FROM equipment_status WHERE device_id = 'BNC-2024001' AND ts >= '2024-10-20 00:00:00' ORDER BY health_score DESC LIMIT 20; # 前后时间段对比 SELECT 'before_failure' as period, AVG(temperature) as avg_temp, STDDEV(temperature) as temp_stdev FROM equipment_status WHERE device_id = 'BNC-2024001' AND ts >= '2024-10-20 08:00:00' AND ts < '2024-10-20 10:00:00' UNION ALL SELECT 'after_failure' as period, AVG(temperature) as avg_temp, STDDEV(temperature) as temp_stdev FROM equipment_status WHERE device_id = 'BNC-2024001' AND ts >= '2024-10-20 10:00:00' AND ts < '2024-10-20 12:00:00';
# 各矿区设备能耗汇总 SELECT region, COUNT(DISTINCT device_id) as device_count, AVG(power_consumption) as avg_power, SUM(power_consumption) as total_power, AVG(efficiency) as avg_efficiency FROM equipment_status WHERE ts >= '2024-10-01 00:00:00' AND ts < '2024-10-31 23:59:59' GROUP BY region ORDER BY total_power DESC; # 不同型号设备能效对比 SELECT model, COUNT(DISTINCT device_id) as device_count, AVG(power_consumption) as avg_power, AVG(efficiency) as avg_efficiency, AVG(power_consumption)/AVG(efficiency) as power_per_unit FROM equipment_status WHERE ts >= '2024-10-01' AND ts < '2024-11-01' GROUP BY model HAVING COUNT(*) > 100 ORDER BY avg_efficiency DESC; # 月度能耗趋势分析 SELECT DATE_FORMAT(ts, '%Y-%m') as month, region, SUM(power_consumption) as monthly_power, AVG(efficiency) as monthly_efficiency FROM equipment_status WHERE ts >= '2024-01-01' AND ts < '2024-11-01' GROUP BY month, region ORDER BY month, region; # 能耗效率排名分析 SELECT region, model, AVG(efficiency) as eff_score, AVG(power_consumption) as power_score, (AVG(efficiency) - 0.7 * AVG(power_consumption)/1000) as composite_score FROM equipment_status WHERE ts >= '2024-10-01' GROUP BY region, model HAVING COUNT(*) > 50 ORDER BY composite_score DESC; # 设备负载率与能耗关系 SELECT CASE WHEN load_rate < 0.3 THEN '低负载' WHEN load_rate < 0.7 THEN '中负载' ELSE '高负载' END as load_level, AVG(power_consumption) as avg_power, AVG(efficiency) as avg_efficiency, COUNT(*) as sample_count FROM equipment_status WHERE ts >= '2024-10-20' GROUP BY load_level ORDER BY avg_efficiency DESC;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70014783/viewspace-3114039/ ,如需转载,请注明出处,否则将追究法律责任。