目 录CONTENT

文章目录

MySQL实用查询

陌念
2022-12-15 / 0 评论 / 0 点赞 / 8 阅读 / 0 字
温馨提示:
本文最后更新于2024-06-12,若内容或图片失效,请留言反馈。 部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1. 查询各个分段的总数

SELECT
	count( CASE WHEN rating_score BETWEEN 90 AND 100 THEN 1 END ) AS AAA,
	count( CASE WHEN rating_score BETWEEN 85 AND 89 THEN 1 END ) AS AA_jia,
	count( CASE WHEN rating_score BETWEEN 80 AND 84 THEN 1 END ) AS AA,
	count( CASE WHEN rating_score BETWEEN 75 AND 79 THEN 1 END ) AS AA_jian,
	count( CASE WHEN rating_score BETWEEN 70 AND 74 THEN 1 END ) AS A_jia,
	count( CASE WHEN rating_score BETWEEN 65 AND 69 THEN 1 END ) AS A,
	count( CASE WHEN rating_score BETWEEN 60 AND 64 THEN 1 END ) AS A_jian,
	count( CASE WHEN rating_score BETWEEN 55 AND 59 THEN 1 END ) AS BBB,
	count( CASE WHEN rating_score < 55 THEN 1 END ) AS BB_jixia,
	count( CASE WHEN rating_status = 0 THEN 1 END ) AS no_rating 
FROM
	rcd_rating;

2. 查询最近七天的总数

SELECT
	count(*) count 
FROM
	( SELECT * FROM rcd_rating WHERE DATE_SUB( CURDATE(), INTERVAL 7 DAY ) <= date( create_time )) as r;

3. 查询最近七天每天的总数(按照天数分组)

SELECT
	DATE_FORMAT( r.create_time, '%Y-%m-%d' ) days,
	count(*) count 
FROM
	(SELECT * FROM rcd_rating WHERE DATE_SUB( CURDATE(), INTERVAL 7 DAY ) <= date( create_time )) AS r
GROUP BY days;


0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin
  3. QQ打赏

    qrcode qq

评论区