mysql知识点整理

行转列问题

https://www.cnblogs.com/yinjw/p/11767282.html

日期函数

https://baijiahao.baidu.com/sid=1608326786755050044&wfr=spider&for=pc

取得‘2008-01-10’(date)其中的年份-月份,两种做法。

1.concat(year(date),'-',month(date))

2.date_format(date,'%y-%m')

date(now()) 等价于 curdate()


获取时间中的时分秒

小时部分:  datepart(hour,列名)
分钟部分:  datepart(minute ,列名)
秒部分:    datepart(second, 列名)

month函数

求下个月过生日的学生id(一种特殊情况,当当前时间为12月份时)

s_id:学生id
birth_date:学生生日
表为student

select s_id from student  where

case when month(date(now)) = 12 then month(birth_date) = 1 

else month(birth_date) = month(date(now))+1 end;

week函数

获取日期为一年中的第几周

WEEK(date[,mode])

一般情况下mode参数省略就行。
在这里插入图片描述

convert

转换类型
https://www.cnblogs.com/phpk/p/10931804.html

case when then else end

https://blog.csdn.net/u013514928/article/details/80969949

if ifnull nullif isnull

https://blog.csdn.net/pan_junbiao/article/details/85928004?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

substr/substring

https://blog.csdn.net/csdn_0_001/article/details/79496332

concat

https://baijiahao.baidu.com/s?id=1595349117525189591&wfr=spider&for=pc

pencentile

-- 获取income字段的top10%的阈值
select percentile(CAST (salary AS int),0.9)) as income_top10p_threshold from table_1;


-- 获取income字段的10个百分位点
select percentile(CAST (salary AS int),array(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)) as income_percentiles
from table_1;

留存 留存率

https://zhuanlan.zhihu.com/p/33728880

https://zhuanlan.zhihu.com/p/68158220

eg.
在这里插入图片描述求出次日用户的留存,三日留存和七日留存。
思路:以次日留存举例,使用自连接 取两个天数(通过两次select)相减等于1(利用case when )时,通过count统计用户数

select a.uid,count( distinct case when day2-day1 = 1 then a.uid end )as 次留

from 

(select uid,date_format(dayno,'%y%m%d') as day1 from aui
where app_name = 相机 )a

left join 

 (select uid,data_format(dayno,'%y%m%d') as day2 from aui 
where app_name = 相机) b

on a.uid = b.uid

group by a.day1

计算连续登录天数

https://www.jianshu.com/p/77597eadd3cc

优化和索引

https://blog.csdn.net/weixin_44504146/article/details/92737613

cast函数

在合适的条件下转换数据类型
https://www.cnblogs.com/accumulater/p/6149669.html

timestamp 和 datetime 的区别

https://www.cnblogs.com/mxwz/p/7520309.html

pencent_rank,cume_list

https://yq.aliyun.com/articles/593692

lag(expr,n),lead(expr,n)

https://zhuanlan.zhihu.com/p/116012207

FIRST_VALUE(expr),LAST_VALUE(expr)

https://zhuanlan.zhihu.com/p/116012207

业务专题

https://zhuanlan.zhihu.com/p/116012207

SIGN函数

返回数字的正负

sign(4.5)  返回1 
sign(0) 返回0

求 众数,中位数

https://www.jianshu.com/p/bd63f5b64a27

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值