-- ====================================
-- 步骤2：检查iot_device_data表中的实际数据
-- ====================================

-- 2.1 检查项圈设备数据（device_type=4）
SELECT 
    device_id as '设备ID',
    device_type as '设备类型',
    voltage as '电压',
    temperature as '温度',
    steps as '步数',
    same_day_steps as '当日步数',
    latitude as '纬度',
    longitude as '经度',
    server_device_id as '主机设备ID',
    update_time as '更新时间'
FROM iot_device_data 
WHERE device_type = 4 
ORDER BY update_time DESC
LIMIT 10;

-- 2.2 检查耳标设备数据（device_type=2）
SELECT 
    device_id as '设备ID',
    device_type as '设备类型',
    voltage as '电压',
    temperature as '温度',
    steps as '步数',
    same_day_steps as '当日步数',
    latitude as '纬度',
    longitude as '经度',
    server_device_id as '主机设备ID',
    update_time as '更新时间'
FROM iot_device_data 
WHERE device_type = 2 
ORDER BY update_time DESC
LIMIT 10;

-- 2.3 检查主机设备数据（device_type=1）
SELECT 
    device_id as '设备ID',
    device_type as '设备类型',
    voltage as '电压',
    temperature as '温度',
    latitude as '纬度',
    longitude as '经度',
    update_time as '更新时间'
FROM iot_device_data 
WHERE device_type = 1 
ORDER BY update_time DESC
LIMIT 10;

-- 2.4 检查所有字段的最大长度
SELECT 
    '项圈设备' as '设备类型',
    'latitude' as '字段名',
    MAX(LENGTH(CAST(latitude AS CHAR))) as '最大长度',
    MAX(CHAR_LENGTH(CAST(latitude AS CHAR))) as '最大字符长度'
FROM iot_device_data WHERE device_type = 4
UNION ALL
SELECT 
    '项圈设备' as '设备类型',
    'longitude' as '字段名',
    MAX(LENGTH(CAST(longitude AS CHAR))) as '最大长度',
    MAX(CHAR_LENGTH(CAST(longitude AS CHAR))) as '最大字符长度'
FROM iot_device_data WHERE device_type = 4
UNION ALL
SELECT 
    '项圈设备' as '设备类型',
    'voltage' as '字段名',
    MAX(LENGTH(CAST(voltage AS CHAR))) as '最大长度',
    MAX(CHAR_LENGTH(CAST(voltage AS CHAR))) as '最大字符长度'
FROM iot_device_data WHERE device_type = 4
UNION ALL
SELECT 
    '项圈设备' as '设备类型',
    'temperature' as '字段名',
    MAX(LENGTH(CAST(temperature AS CHAR))) as '最大长度',
    MAX(CHAR_LENGTH(CAST(temperature AS CHAR))) as '最大字符长度'
FROM iot_device_data WHERE device_type = 4
UNION ALL
SELECT 
    '项圈设备' as '设备类型',
    'server_device_id' as '字段名',
    MAX(LENGTH(server_device_id)) as '最大长度',
    MAX(CHAR_LENGTH(server_device_id)) as '最大字符长度'
FROM iot_device_data WHERE device_type = 4;

-- 2.5 检查设备数量
SELECT 
    device_type as '设备类型',
    CASE device_type
        WHEN 1 THEN '主机'
        WHEN 2 THEN '耳标'
        WHEN 4 THEN '项圈'
        ELSE '未知'
    END as '设备类型名称',
    COUNT(*) as '设备数量'
FROM iot_device_data 
WHERE device_type IN (1, 2, 4)
GROUP BY device_type;

