FROM_UNIXTIME:日期格式转换函数
CONVERT ( event_time / 1000, signed ):时间戳去除后三位,signed转换为整数
SELECT
count( 1 ),
'year' AS flag
FROM
event_business
WHERE
FROM_UNIXTIME( CONVERT ( event_time / 1000, signed ), '%Y' ) = date_format( now( ), '%Y' ) UNION ALL
(
SELECT
count( 1 ),
'month' AS flag
FROM
event_business
WHERE
FROM_UNIXTIME( CONVERT ( event_time / 1000, signed ), '%Y-%m' ) = date_format( now( ), '%Y-%m' )
) UNION ALL
(
SELECT
count( 1 ),
'day' AS flag
FROM
event_business
WHERE
FROM_UNIXTIME( CONVERT ( event_time / 1000, signed ), '%Y-%m-%d' ) = date_format( now( ), '%Y-%m-%d' )
)
或者
select
sum(case when FROM_UNIXTIME(CONVERT(event_time/1000 , signed),'%Y') = date_format(now(),'%Y') then 1 else 0 end) as year,
sum(case when FROM_UNIXTIME(CONVERT(event_time/1000 , signed),'%Y%m') = date_format(now(),'%Y%m') then 1 else 0 end) as month
FROM event_business
运行效果