题解 | #21年8月份练题总数#
21年8月份练题总数
https://www.nowcoder.com/practice/b8f30b239b454ed490367b53ea95607d
select count(distinct device_id) as did_cnt, count(device_id) as question_cnt #或者count(question_id) as question_cnt 通过 # count(distinct question_id) as question_cnt G了 # 不可以用distinct 问的是题的总数,而不是有几类题。 from question_practice_detail where month(date) = 8 and year(date) = 2021;
查找2021 8月份的方法
#date(最常用,其格式为:YYYY-MM-DD) # month year函数 where month(date) = 8 and year(date) = 2021; #date_format() where date_format(date,'%Y%m') = '202108'; #Y where date_format(date,'%y%m') = '2108' ;#y #like where date like '2021-08%'; #substring():截取字符串中介于两个指定下标之间的字符。 where substring(date,1,7) = '2021-08' #mid 有点像substring() where mid(date,1,7) = '2021-08' #substring_index(“待截取有用部分的字符串”,“截取数据依据的字符”,截取字符的位置N) where substring_index(date,'-',2) = '2021-08'