SQL
记录sql查询的一些难点
一只用R的浣熊
算法小白
展开
-
Hive表随机抽样
Hive表随机抽样翻译 2022-08-09 11:37:38 · 746 阅读 · 0 评论 -
PostgreSQL如何筛选连续3日登录用户
原始数据uid:用户编号day:登录日期(已去重)具体思路使用窗口函数按照uid分组对day进行排序如果连续登录,则day - rank 应该相同对day-rank进行group by,若count>=3即可说明该用户连续3日登录。SQL实现...原创 2020-05-25 00:17:58 · 836 阅读 · 0 评论 -
Leetcode中的Nth Highest Salary
问题描述找出第N大的数,例如:IdSalary11002100320042005300查询结果NNth Salary1300220031004NULL解决方案1.使用limit函数先按照从大到小的顺序筛选出distinct后的N个Salary,然后取其中的最小Salary即可,SQL如下:CREATE FUNCTION getNthHighestSalary(N INT) RETUR原创 2020-05-24 18:54:21 · 176 阅读 · 0 评论 -
WIN10系统安装PostgreSQL并用R语言连接
PostgreSQL的安装和连接原创 2020-05-17 14:21:24 · 525 阅读 · 0 评论 -
AWS Athena 数据库解析json格式字段
提出问题在Athena数据库中遇到入下json格式的字段:{"name": "Susan Smith","org": "engineering","projects": [ {"name":"project1", "completed":false}, {"name":"project2", "completed":true} ]}希望解析该字段,...翻译 2019-05-24 15:13:37 · 1217 阅读 · 0 评论 -
AWS Athena中的unnest用法
将[[a,0,1],[b,0,2]]转化为按列显示原创 2019-06-24 11:20:12 · 680 阅读 · 0 评论 -
Athena SQL优化(持续更新)
优化join在连接两张表时,大表在左,小表在右When you join two tables, specify the larger table on the left side of join and the smaller table on the right side of the join. Presto distributes the table on the right to ...翻译 2019-06-24 18:09:06 · 694 阅读 · 0 评论 -
PostgreSQL处理jsonb中的arrays of array 类型
PostgreSQL处理jsonb中的arrays of array 类型一、提出问题在postgre数据库,遇到了数组内嵌套数组的jsonb存储格式,如下:SELECT *FROM public.keyword_trend查询结果:其中,history一栏[[“2014-05-11”,70],[“2014-05-18”,69]…]中,每个数组包含两项,分别为日期和得分,我们希望查询...原创 2019-05-13 17:17:43 · 3697 阅读 · 1 评论