到期的设备数量: 用 DATEDIFF
SELECT d.*
FROM jtl_device d
LEFT JOIN jtl_device_detail dd ON dd.`device_id` = d.`device_id`
WHERE DATEDIFF(d.expiration_time,NOW()) <0 AND d.`company_id` = '1577945251258504' AND d.`del_flag` = 0 AND dd.`del_flag`=0
即将到期的(当前时间向前推30天) 注意里边包含 已到期数据
SELECT d.* FROM jtl_device d
LEFT JOIN jtl_device_detail dd ON d.device_id = dd.device_id
WHERE DATE_FORMAT(d.expiration_time,'%Y-%m-%d')<=DATE_ADD(CURDATE(),INTERVAL 30 DAY) AND d.`company_id` = '1577945251258504' AND d.`del_flag`=0 AND dd.`del_flag` = 0
未到期的:
总设备数量- 即将到期的-到期的