0
点赞
收藏
分享

微信扫一扫

MySql数量统计sql

阎小妍 2022-04-23 阅读 47


-- 统计创建工单数量,

SELECT
date_add(DATE_ADD(curdate(), INTERVAL - DAY(curdate()) + 2 DAY), INTERVAL (cast( help_topic_id AS signed INTEGER ) - 1 ) DAY ) date ,
(SELECT count(temp_id) from ows_order oo where left(oo.create_time, 10) = date) total_count
from mysql.help_topic
where help_topic_id  < day(curdate())
order by total_count desc;



-- 完成工单数量(按时、超时都算完成)
SELECT
date_add(DATE_ADD(curdate(), INTERVAL - DAY(curdate()) + 2 DAY), INTERVAL (cast( help_topic_id AS signed INTEGER ) - 1 ) DAY ) date ,
(SELECT count(temp_id) from ows_order oo where left(oo.create_time, 10) = date and oo.completed_type in (1,2)) total_count
from mysql.help_topic
where help_topic_id  < day(curdate())
order by total_count desc;


-- ,关闭工单数量,

SELECT
date_add(DATE_ADD(curdate(), INTERVAL - DAY(curdate()) + 2 DAY), INTERVAL (cast( help_topic_id AS signed INTEGER ) - 1 ) DAY ) date ,
(SELECT count(temp_id) from ows_order oo where left(oo.create_time, 10) = date and oo.closed_time is not null) total_count
from mysql.help_topic
where help_topic_id  < day(curdate())
order by total_count desc
;






-- 当月  创建,完成,关闭
(select count(temp_id) q from ows_order where left(create_time, 7) =  DATE_FORMAT(NOW(),'%Y-%m') )
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 7) =  DATE_FORMAT(NOW(),'%Y-%m') and completed_type in (1,2)
)
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 7) =  DATE_FORMAT(NOW(),'%Y-%m') and closed_time is not null
)



-- 选择日期
(select count(temp_id) q from ows_order where left(create_time, 7) =  '2022-03' )
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 7) = '2022-03' and completed_type in (1,2)
)
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 7) =  '2022-03' and closed_time is not null
)


-- 传参循环 周
(select count(temp_id) q from ows_order where left(create_time, 10) >=  '2022-04-01' and left(create_time, 10) <=  '2022-04-07'  )
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 10) >=  '2022-04-01' and left(create_time, 10) <=  '2022-04-07' and completed_type in (1,2)
)
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 10) >=  '2022-04-01' and left(create_time, 10) <=  '2022-04-07' and closed_time is not null
);


(select count(temp_id) q from ows_order where left(create_time, 10) >=  '2022-04-07' and left(create_time, 10) <=  '2022-04-14'  )
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 10) >=  '2022-04-07' and left(create_time, 10) <=  '2022-04-14' and completed_type in (1,2)
)
UNION all
(
select count(temp_id) q from ows_order where left(create_time, 10) >=  '2022-04-07' and left(create_time, 10) <=  '2022-04-14' and closed_time is not null
)






-- 任务二:
SELECT user_id, count(temp_id) q from ows_order where left(create_time, 7) = DATE_FORMAT(NOW(),'%Y-%m') and completed_type in (1,2)  GROUP BY user_id ORDER BY q desc limit 15




举报

相关推荐

0 条评论