首页 > 数据库 >sql练习--计算用户8月每天的练题数量

sql练习--计算用户8月每天的练题数量

时间:2022-09-23 02:11:08浏览次数:47  
标签:-- practice question detail 练题 2021 sql date day

描述

题目:现在运营想要计算出2021年8月每天用户练习题目的数量,请取出相应数据。   示例:question_practice_detail
id device_id question_id result date
1 2138 111 wrong 2021-05-03
2 3214 112 wrong 2021-05-09
3 3214 113 wrong 2021-06-15
4 6543 111 right 2021-08-13
5 2315 115 right 2021-08-13
6 2315 116 right 2021-08-14
7 2315 117 wrong 2021-08-15
……        
根据示例,你的查询应返回以下结果:
day question_cnt
13 5
14 2
15 3
16 1
18 1

 

select extract(day from date)day,count(*)question_cnt
from question_practice_detail
where date in(
    select date from 
    question_practice_detail
    where year(date) = 2021 and month(date) = 8
)
group by day
select
    case when year(date) = 2021 and month(date) = 8
    then extract(day from date)
    else null end day,
    count(*) question_cnt
from question_practice_detail
group by day    
select extract(day from date) day,count(*)question_cnt
from question_practice_detail
where date_format(date,"%Y-%m")="2021-08"
group by day
select day(date) `day`,count(question_id) question_cnt
from question_practice_detail
where date_format(date, "%Y-%m")="2021-08"
group by day
select
day(date) as `day`,
count(question_id) question_cnt
from question_practice_detail
where month(date) = 8 and year(date) = 2021
group by date

  • 限定条件:2021年8月,写法有很多种,比如用year/month函数的year(date)=2021 and month(date)=8
  • 比如用date_format函数的date_format(date, "%Y-%m")="202108"
  • 每天:按天分组group by date
  • 题目数量:count(question_id)

标签:--,practice,question,detail,练题,2021,sql,date,day
From: https://www.cnblogs.com/xinger123/p/16721403.html

相关文章

  • 我 在 理论物理吧 发的 多个 楼层 和 回复 被 接连 删除
    我 在 理论物理吧 发的 多个楼层和回复被接连删除  。 @ddx7171  @dons222  @物空必能  @happyird  @求实2468      还好有......
  • mysql练习--计算25岁以上和以下的用户数量
    描述题目:现在运营想要将用户划分为25岁以下和25岁及以上两个年龄段,分别查看这两个年龄段用户数量本题注意:age为null也记为25岁以下 示例:user_profileiddevic......
  • 归并排序
    平均时间复杂度:O(nlogn)最佳时间复杂度:O(n)最差时间复杂度:O(nlogn)空间复杂度:O(n)排序方式:In-place稳定性:稳定defmerge_sort(num1,num2):#按大小合并数组......
  • sql练习--查看不同年龄段的用户明细
    描述题目:现在运营想要将用户划分为20岁以下,20-24岁,25岁及以上三个年龄段,分别查看不同年龄段用户的明细情况,请取出相应数据。(注:若年龄为空请返回其他。)   示例:user......
  • 爬取BiliBili视频
    https://github.com/BtbN/FFmpeg-Builds/releases/tag/latest这是ffmpeg下载地址,下载好要配置环境变量,合成视频要用到,因为B站的视频和音频是分开的花了段时间分析的下Bi......
  • DSC共享存储集群的搭建
    首先进行环境准备硬件:两台相同配置机器,3G内存,23G本地磁盘,2块网卡,另有一块共享磁盘20G。操作系统:Ubuntu64位。DM各种工具位于目录:/dm8/tool。配置文件位于目录:/dm8/da......
  • Markdown初识
    Markdown初识标题#+空格+标题名字,#越多标题级数越高字体1.粗体:两边各**Hello,World2.斜体:两边各*Hello,World3.斜体加粗:两边各***Hello,World4.删除线:两边各~~Hel......
  • [FLET] 01 可以拖动的方块
    fromtypingimportListimportfletfromfletimport(Container,Draggable,DragTarget,Page,Row,Text,alignment,colors,......
  • 实验2:Open vSwitch虚拟交换机实践
    实验2:OpenvSwitch虚拟交换机实践一、实验目的能够对OpenvSwitch进行基本操作;能够通过命令行终端使用OVS命令操作OpenvSwitch交换机,管理流表;能够通过Mininet的Pytho......
  • 《一年顶十年》
    一年顶十年2020年北京联合出版公司出版的图书《一年顶十年》是2020年北京联合出版公司出版发行的图书,作者是剽悍一只猫。 内容简介这是一套完整的个人影响力......