伍继sql优化策略 377 B

1234567891011121314
  1. SELECT
  2. DATE_FORMAT(dataTime, '%Y-%m-%d') monthTime,
  3. COUNT(ht.id) as aCount,
  4. d.site_id
  5. FROM
  6. `ht_analog_data` as ht
  7. INNER JOIN device as d
  8. ON ht.deviceName = d.device_code
  9. INNER JOIN user_site as us
  10. on d.site_id = us.site_id
  11. WHERE
  12. dataTime BETWEEN '1900-5-6 00:00:00' AND '2021-8-6 00:00:00'
  13. and us.user_id = 1
  14. GROUP BY monthTime,d.site_id