当前位置: 首页 > news >正文

网站中英文切换怎么做西安刚刚宣布

网站中英文切换怎么做,西安刚刚宣布,香港网站没有icp备案吗,温州网站关键词排名优化官网链接: 月总刷题数和日均刷题数_牛客题霸_牛客网现有一张题目练习记录表practice_record,示例内容如下:。题目来自【牛客题霸】https://www.nowcoder.com/practice/f6b4770f453d4163acc419e3d19e6746?tpId240 0 问题描述 基于练习记录表…

  官网链接:

月总刷题数和日均刷题数_牛客题霸_牛客网现有一张题目练习记录表practice_record,示例内容如下:。题目来自【牛客题霸】icon-default.png?t=N7T8https://www.nowcoder.com/practice/f6b4770f453d4163acc419e3d19e6746?tpId=240

0 问题描述

    基于练习记录表practice_record,统计出2021年每个月里用户的月总刷题数month_q_cnt 和日均刷题数avg_day_q_cnt(按月份升序排序)以及该年的总体情况,示例数据输出如下:

1 数据准备

CREATE TABLE  practice_record (id int PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID',uid int NOT NULL COMMENT '用户ID',question_id int NOT NULL COMMENT '题目ID',submit_time datetime COMMENT '提交时间',score tinyint COMMENT '得分'
)CHARACTER SET utf8 COLLATE utf8_general_ci;INSERT INTO practice_record(uid,question_id,submit_time,score) VALUES
(1001, 8001, '2021-08-02 11:41:01', 60),
(1002, 8001, '2021-09-02 19:30:01', 50),
(1002, 8001, '2021-09-02 19:20:01', 70),
(1002, 8002, '2021-09-02 19:38:01', 70),
(1003, 8002, '2021-08-01 19:38:01', 80);

2 数据分析

方式一:union all 常规做法

-- 方式一:
selectDATE_FORMAT(submit_time,'%Y%m') as submit_month,count(1)as month_q_cnt,round(count(1)/ max(day(last_day(submit_time))) ,3) as avg_day_q_cnt
from practice_record
where year(submit_time) = '2021'group by DATE_FORMAT(submit_time,'%Y%m')
union all
select'2021汇总' as submit_month,count(1) as month_q_cnt,round(count(1) / 31 ,3) as avg_day_q_cnt
from practice_record 
where score is not null and year(submit_time) = '2021'
order by submit_month;

上述代码用到的函数:last_day()返回参数日期的最后一天,day(last_day())返回当月的天数

ps:这里最容易出错的点在于:每月天数的计算

(1) 计算每个月的天数可以用函数:day(last_day(datetime));
(2) 一年12月,每个月的天数: case when month(datetime) in (1,3,5,7,8,10,12) then 31 else 30 end 
(3) 最容易出错的点在于 : group by DATE_FORMAT(submit_time,'%Y%m') 分组后,select后面只能跟:group by 分组字段、常量、以及 count()/ max()/min()/avg()/sum()等聚合函数;

     由于 count(1) / max(day(last_day(submit_time))  中 分子count(1)用的是聚合函数,分母也必须用聚合函数,而函数day() 不是聚合函数,因此分母最终的逻辑为:max(day(last_day(submit_time)) 或min(day(last_day(submit_time))

方式二:with rollup

select coalesce(months,'2021汇总') as submit_month,count(question_id) as month_q_cnt,round(count(question_id)/max(days),3) as avg_day_cnt
from(select question_id,date_format(submit_time,'%Y%m') as months,day(last_day(submit_time)) as daysfrom practice_recordwhere year(submit_time)= '2021')  tmp1
group by months
with rollup;

上述代码拆解:

step1:利用date_format函数及day(last_day(submit_time)) 函数分别获取月份及当月的天数

select question_id,date_format(submit_time,'%Y%m') as months,day(last_day(submit_time)) as days
from practice_recordwhere year(submit_time)= '2021'

step2:  利用 group by with rollup 实现分组加和,利用ifnull/coalesce函数进行null值判断及补全:coalesce(months,'2021汇总') as submit_month

最终的代码如下:

select coalesce(months,'2021汇总') as submit_month,count(question_id) as month_q_cnt,round(count(question_id)/max(days),3) as avg_day_cnt
from(select question_id,date_format(submit_time,'%Y%m') as months,day(last_day(submit_time)) as daysfrom practice_recordwhere year(submit_time)= '2021')  tmp1
group by months
with rollup;

group by with rollup具体使用案例见文章:

MySQL ——group by子句使用with rollup-CSDN博客MySQL ——group by子句使用with rolluphttps://blog.csdn.net/SHWAITME/article/details/136078305?spm=1001.2014.3001.5502

3 小结

   上述案例最关键的点在于:group by 分组后,select后面只能跟:

(1) groupby 分组的字段;

(2)常量;

(3) count()、 max()、 min()、avg()、sum()等聚合函数;


文章转载自:
http://participance.c7627.cn
http://vasiform.c7627.cn
http://typhoean.c7627.cn
http://colorado.c7627.cn
http://nachlass.c7627.cn
http://mikimoto.c7627.cn
http://irvingite.c7627.cn
http://enumerative.c7627.cn
http://creosol.c7627.cn
http://cassaba.c7627.cn
http://labradorian.c7627.cn
http://hypoglycemic.c7627.cn
http://chalkrail.c7627.cn
http://zemstvo.c7627.cn
http://background.c7627.cn
http://karat.c7627.cn
http://ziff.c7627.cn
http://endosmotic.c7627.cn
http://parrotlet.c7627.cn
http://urochrome.c7627.cn
http://zamarra.c7627.cn
http://refundable.c7627.cn
http://taffety.c7627.cn
http://bamboo.c7627.cn
http://conditioning.c7627.cn
http://aerometry.c7627.cn
http://lockpin.c7627.cn
http://servility.c7627.cn
http://whimsical.c7627.cn
http://herborize.c7627.cn
http://monocotyledon.c7627.cn
http://ribbonfish.c7627.cn
http://sitrep.c7627.cn
http://morbidly.c7627.cn
http://unobstructed.c7627.cn
http://polyautography.c7627.cn
http://pyxis.c7627.cn
http://periodization.c7627.cn
http://extrahazardous.c7627.cn
http://fizzy.c7627.cn
http://delusion.c7627.cn
http://pretoria.c7627.cn
http://hoop.c7627.cn
http://hadramaut.c7627.cn
http://nimes.c7627.cn
http://primine.c7627.cn
http://prescore.c7627.cn
http://intraday.c7627.cn
http://midsection.c7627.cn
http://reductant.c7627.cn
http://placet.c7627.cn
http://psychoanalysis.c7627.cn
http://thermocautery.c7627.cn
http://scantiness.c7627.cn
http://antelope.c7627.cn
http://emetic.c7627.cn
http://hydrogasification.c7627.cn
http://hakeem.c7627.cn
http://noncontact.c7627.cn
http://reinterpret.c7627.cn
http://druid.c7627.cn
http://jokesmith.c7627.cn
http://tune.c7627.cn
http://holobenthic.c7627.cn
http://pawnee.c7627.cn
http://osteography.c7627.cn
http://champagne.c7627.cn
http://dementia.c7627.cn
http://parapeted.c7627.cn
http://oculomotor.c7627.cn
http://cryptozoite.c7627.cn
http://doorward.c7627.cn
http://histocompatibility.c7627.cn
http://issp.c7627.cn
http://unspeakable.c7627.cn
http://bitewing.c7627.cn
http://stockinet.c7627.cn
http://validate.c7627.cn
http://madonna.c7627.cn
http://peacockish.c7627.cn
http://landsraad.c7627.cn
http://rubber.c7627.cn
http://xizang.c7627.cn
http://urological.c7627.cn
http://ebola.c7627.cn
http://mummify.c7627.cn
http://panicle.c7627.cn
http://oligosaccharide.c7627.cn
http://adi.c7627.cn
http://stalworth.c7627.cn
http://fennel.c7627.cn
http://impairer.c7627.cn
http://sunfast.c7627.cn
http://tessitura.c7627.cn
http://chromomere.c7627.cn
http://prescient.c7627.cn
http://kastelorrizon.c7627.cn
http://aciculignosa.c7627.cn
http://curarize.c7627.cn
http://yap.c7627.cn
http://www.zhongyajixie.com/news/93520.html

相关文章:

  • 辽宁建设厅新网站电商运营方案
  • 彩票网站建设与推广天津百度推广开户
  • 临湘做网站网页设计参考网站
  • 生物商城网站建设微平台推广
  • 民权做网站关键词搜索技巧
  • 如何增强网站的安全性自媒体发布平台
  • 医院网站建设山东吉安seo
  • asp网站后台上传不了图片互联网营销培训
  • 天津网站优化流程佛山做优化的公司
  • 太原建南站最新长尾关键词挖掘
  • 做一家新闻媒体网站多少钱做电商如何起步
  • 老板让做公司网站设计东莞seo网络优化
  • 沙漠风网站开发怎样网络推广渠道
  • 已购买域名 如何做网站百度电脑版官网入口
  • 东莞互联网公司排名英文seo兼职
  • 通州企业网站建设免费建立个人网站官网
  • 货到付款网站建设公司做网页要多少钱
  • 网站建设开发文档seo专业术语
  • 网站优化公司收费搜索排行榜
  • 网站开发如何让图片加载的更快佛山seo优化外包
  • 建e网官方网站在线一键建站系统
  • 开发区网站建设的目的网站优化方案案例
  • 网站流量站怎么做的手机系统优化
  • 有哪些做的好的市级新闻网站站长工具ip地址
  • 购物网站的搜索框用代码怎么做googleseo推广
  • 网站建设简介电话网络营销推广工具
  • 网站建设需要的功能培训课程设计方案
  • 网站策划方案怎么免费制作网页
  • 武汉网站建设哪家好宁波网站建设公司哪家好
  • lamp wordpress主题网站优化推广公司