#查询表的索引 SHOW INDEX FROM 表名称 #删除表的索引 DROP INDEX STREET ON 表名称(字段);
#实时数据 where dateTime>=(NOW() - interval 24 hour) #七天的数据 WHERE dateTime >= date_sub(curdate(), interval 7 day) #当日的日期函数 where date = date_sub(curdate(), interval 2 day)
#
interval是减法的意思
时间的格式,传入开始时间和结束时间,只输入当前日期,规定好后面的时分秒
WHERE dateTime >= DATE_FORMAT(STR_TO_DATE(#{startTime, jdbcType=VARCHAR}, ‘%Y-%m-%d‘),‘%Y-%m-%d 00:00:00‘) AND dateTime <= DATE_FORMAT(STR_TO_DATE(#{endTime, jdbcType=VARCHAR}, ‘%Y-%m-%d‘),‘%Y-%m-%d 23:59:59‘)
case when的用法
SELECT CASE WHEN 字段名 = ‘1‘ THEN ‘自住‘ WHEN HOUSE_TYPE = ‘2‘ THEN ‘租住‘ WHEN HOUSE_TYPE = ‘3‘ THEN ‘投亲靠友‘ WHEN HOUSE_TYPE = ‘4‘ THEN ‘酒店‘ WHEN HOUSE_TYPE = ‘5‘ THEN ‘民宿‘ WHEN HOUSE_TYPE = ‘6‘ THEN ‘宿舍‘ WHEN HOUSE_TYPE = ‘7‘ THEN ‘工棚‘ WHEN HOUSE_TYPE = ‘8‘ THEN ‘其他‘ END as `name`, count(1) `value` FROM t_dws_dt_yd_tianfu_healthy_communication WHERE STREET = ‘条件‘ GROUP BY name
另外一种写法
SELECT CASE WHEN HOUSE_TYPE = ‘1‘ THEN ‘自住‘ WHEN HOUSE_TYPE = ‘2‘ THEN ‘租住‘ WHEN HOUSE_TYPE = ‘3‘ THEN ‘投亲靠友‘ WHEN HOUSE_TYPE = ‘4‘ THEN ‘酒店‘ WHEN HOUSE_TYPE = ‘5‘ THEN ‘民宿‘ WHEN HOUSE_TYPE = ‘6‘ THEN ‘宿舍‘ WHEN HOUSE_TYPE = ‘7‘ THEN ‘工棚‘ else ‘其他‘ END as name, count(1) value FROM t_dws_dt_yd_tianfu_healthy_communication WHERE STREET = #{street} GROUP BY name ORDER BY value DESC