and to_days(create_time)=to_days(now())
and YEARWEEK(date_format(create_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1)
and date_format(create_time,'%Y%m') = date_format(now(),'%Y%m')
and date(create_time) between #{animalHeatVo.begTime} and #{animalHeatVo.endTime}
and hour(create_time)>=0 and hour(create_time) <2
and hour(create_time)>=2 and hour(create_time) <4
and hour(create_time)>=4 and hour(create_time) <6
and hour(create_time)>=6 and hour(create_time) <8
and hour(create_time)>=8 and hour(create_time) <10
and hour(create_time)>=10 and hour(create_time) <12
and hour(create_time)>=12 and hour(create_time) <14
and hour(create_time)>=14 and hour(create_time) <16
and hour(create_time)>=16 and hour(create_time) <18
and hour(create_time)>=18 and hour(create_time) <20
and hour(create_time)>=20 and hour(create_time) <22
and hour(create_time)>=22 and hour(create_time) <24
SELECT 1 `name`,count(`status`) value FROM `blade_animal_heat` where
TO_DAYS(create_time)=TO_DAYS(now()) and `status`=1
UNION
SELECT 0 `name`,count(`status`) value FROM `blade_animal_heat` where
TO_DAYS(create_time)=TO_DAYS(now()) and `status`=0
SELECT 1 `name`,count(`status`) value FROM `blade_animal_heat` where
YEARWEEK(date_format(create_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1) and `status`=1
UNION
SELECT 0 `name`,count(`status`) value FROM `blade_animal_heat` where
YEARWEEK(date_format(create_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1) and `status`=0
SELECT 1 `name`,count(`status`) value FROM `blade_animal_heat` where
date_format(create_time,'%Y%m') = date_format(now(),'%Y%m') and `status`=1
UNION
SELECT 0 `name`,count(`status`) value FROM `blade_animal_heat` where
date_format(create_time,'%Y%m') = date_format(now(),'%Y%m') and `status`=0
SELECT * FROM blade_animal_heat
where 1=1
and status=#{animalHeatVo.status}
ORDER BY create_time desc
select DATE_FORMAT(date(subdate(curdate(),date_format(curdate(),'%w')-1)),'%m-%d') time,ifNull(count(*),0) as number
from blade_animal_heat
where
date_format(create_time,'%Y-%m-%d')=date(subdate(curdate(),date_format(curdate(),'%w')-1))
union all
select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 1 day)),'%m-%d') time,ifNull(count(*),0) as number
from blade_animal_heat
where
date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 1 day))
union all
select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 2 day)),'%m-%d') time,ifNull(count(*),0) as number
from blade_animal_heat
where
date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 2 day))
union all
select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 3 day)),'%m-%d') time,ifNull(count(*),0) as number
from blade_animal_heat
where
date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 3 day))
union all
select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 4 day)),'%m-%d') time,ifNull(count(*),0) as number
from blade_animal_heat
where
date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 4 day))
union all
select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 5 day)),'%m-%d') time,ifNull(count(*),0) as number
from blade_animal_heat
where
date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 5 day))
union all
select DATE_FORMAT(DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 6 day)),'%m-%d') time,ifNull(count(*),0) as number
from blade_animal_heat
where
date_format(create_time,'%Y-%m-%d')=DATE(DATE_ADD(subdate(curdate(),date_format(curdate(),'%w')-1), interval 6 day))
select ifnull(b.count,0) as count from
(
SELECT DATE_FORMAT(date_sub(curdate(), interval 6 day),'%Y-%m-%d') as click_date
union all
SELECT DATE_FORMAT(date_sub(curdate(), interval 5 day),'%Y-%m-%d') as click_date
union all
SELECT DATE_FORMAT(date_sub(curdate(), interval 4 day),'%Y-%m-%d') as click_date
union all
SELECT DATE_FORMAT(date_sub(curdate(), interval 3 day),'%Y-%m-%d') as click_date
union all
SELECT DATE_FORMAT(date_sub(curdate(), interval 2 day),'%Y-%m-%d') as click_date
union all
SELECT DATE_FORMAT(date_sub(curdate(), interval 1 day),'%Y-%m-%d') as click_date
union all
SELECT DATE_FORMAT(curdate(),'%Y-%m-%d') as click_date
) a
left join
(
select DATE_FORMAT(create_time,'%Y-%m-%d') as datetime, count(*) as count from blade_animal_heat
where `status`=1
group by DATE_FORMAT(create_time,'%Y-%m-%d')
) b
on
a.click_date = b.datetime
order by a.click_date asc
select count(*) from blade_animal_heat
where status=1
and create_time between #{conditionVo.startTime} and #{conditionVo.endTime}
select status,create_time from blade_animal_heat
where status=1
and create_time between #{conditionVo.startTime} and #{conditionVo.endTime}
select ifnull(count,0) count from
(
SELECT @date := DATE_ADD( @date, INTERVAL + 1 DAY ) days FROM
(
SELECT @date := DATE_ADD( #{conditionVo.startTime}, INTERVAL - 1 DAY ) FROM sys_date
) time
WHERE to_days( @date ) < to_days( #{conditionVo.endTime} )
) a
left join
(
select DATE_FORMAT(create_time,'%Y-%m-%d') as datetime, count(*) as count from blade_animal_heat
where status=1
group by DATE_FORMAT(create_time,'%Y-%m-%d')
) b
on
a.days = b.datetime
SELECT * FROM blade_animal_heat
where 1=1
and status=#{animalHeatVo.status}
ORDER BY create_time desc
select if(1=1,'正常',0) type,ifnull(count(*),0) count from blade_animal_heat where status=0
union all
select if(1=1,'异常',0) type,ifnull(count(*),0) count from blade_animal_heat where status=1