摘要: ### 1. coalesce函数 [coalesce(expr1, expr2, ...) - Returns the first non-null argument if exists. Otherwise, null.](https://spark.apache.org/docs/latest 阅读全文
posted @ 2023-04-12 17:43 ttttttian 阅读(74) 评论(0) 推荐(0)
摘要: ## 1. 背景 已知数据集为: ![](https://img2023.cnblogs.com/blog/2511413/202304/2511413-20230412164847357-1587134933.png) 目的: 计算每个uid的连续活跃天数,并且每一段活跃期内的开始时间和结束时间 阅读全文
posted @ 2023-04-12 17:17 ttttttian 阅读(575) 评论(0) 推荐(0)
摘要: 转载自:[SQL千字总结:如何更好的操练你手上的时间数据](https://mp.weixin.qq.com/s?__biz=MzU5MjkxMDk4Mg==&mid=2247485087&idx=1&sn=07df4d6c33236d05aa8f73f00f51a801&chksm=fe19c97 阅读全文
posted @ 2023-04-12 16:05 ttttttian 阅读(64) 评论(0) 推荐(0)
摘要: ## 1. 背景 有一个这样的数据集:字段和字段的值是两列 ![](https://img2023.cnblogs.com/blog/2511413/202304/2511413-20230412135038294-948703724.png) 目的是将这个数据转换成规整的一个特征是一列的数据: ! 阅读全文
posted @ 2023-04-12 15:22 ttttttian 阅读(463) 评论(0) 推荐(0)
摘要: 1. 删除列 import pandas as pd df.drop("Unnamed: 0", axis=1, inplace=True) 2. 转换列的格式 df["Date"] = df["Date"].astype("datetime64[ns]") df = df.astype({'tra 阅读全文
posted @ 2023-03-10 15:43 ttttttian 阅读(23) 评论(0) 推荐(0)
摘要: ## 计算时间间隔 ### day ``` datediff(大日期, 小日期) ``` ``` SELECT datediff('2009-07-31', '2009-07-30') ``` ![](https://img2023.cnblogs.com/blog/2511413/202303/2 阅读全文
posted @ 2023-03-07 11:34 ttttttian 阅读(27) 评论(0) 推荐(0)
摘要: ## ytd释义 YTD分析属于同比分析类,其特点在于对比汇总值,即从年初第一日值一直至今的值累加。作用在于分析企业中长期的经营绩效。 ### 做法 假定: 有一张销量明细表 | date | 仓库 | sku | 销量 | | | | | | | 2020-01-01 | 杭州仓 | 03045 阅读全文
posted @ 2023-03-01 11:31 ttttttian 阅读(172) 评论(0) 推荐(0)
摘要: sql sever默认null最小 ### 升序排序 null值在最前面,若要放在后面,则: ``` order by case when col is null then 1 else 0 end, col ``` ### 降序排序 null值在最后面,若要放在前面,则: ``` order by 阅读全文
posted @ 2023-02-28 16:50 ttttttian 阅读(478) 评论(0) 推荐(0)
摘要: ## lag https://spark.apache.org/docs/latest/api/sql/#lag lag(input[, offset[, default]]) OVER (PARTITION BY a ORDER BY b) input - 求lag的目标字段 offset - l 阅读全文
posted @ 2023-02-28 16:40 ttttttian 阅读(286) 评论(0) 推荐(0)
摘要: ### 背景 有一张表: | date | store_id | sku | sales| | | | | | | 2023-01-01 | CK005 | 03045 |50 | date 代表交易日期,store_id代表门店编号,sku代表商品,sales代表销量。 ### 问题 求出2022 阅读全文
posted @ 2023-02-15 09:47 ttttttian 阅读(296) 评论(0) 推荐(0)