Skip to content

Commit

Permalink
blog update
Browse files Browse the repository at this point in the history
blog update
  • Loading branch information
xxzuo committed Mar 25, 2024
1 parent 504a455 commit 42ad330
Show file tree
Hide file tree
Showing 17 changed files with 1,382 additions and 8 deletions.
6 changes: 2 additions & 4 deletions _config.fluid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ index:

# 为空则按 hexo config.subtitle 显示
# If empty, text based on `subtitle` in hexo config
text: "coding"
text: " O_o "

# 通过 API 接口作为首页副标题的内容,必须返回的是 JSON 格式,如果请求失败则按 text 字段显示,该功能必须先开启 typing 打字机功能
# Subtitle of the homepage through the API, must be returned a JSON. If the request fails, it will be displayed in `text` value. This feature must first enable the typing animation
Expand Down Expand Up @@ -831,13 +831,11 @@ about:
subtitle:
avatar: /img/avatar.png
name: "xxzuo"
intro: "Java"
intro: ""
# 更多图标可从 https://hexo.fluid-dev.com/docs/icon/ 查找,`class` 代表图标的 css class,添加 `qrcode` 后,图标不再是链接而是悬浮二维码
# More icons can be found from https://hexo.fluid-dev.com/docs/en/icon/ `class` is the css class of the icon. If adding `qrcode`, The icon is no longer a link, but a hovering QR code
icons:
- { class: "iconfont icon-github-fill", link: "https://github.com/xxzuo", tip: "GitHub" }
- { class: "iconfont icon-douban-fill", link: "https://douban.com", tip: "豆瓣" }
- { class: "iconfont icon-wechat-fill", qrcode: "/img/favicon.png" }


#---------------------------
Expand Down
63 changes: 63 additions & 0 deletions source/_posts/SQL相关/SQL生成连续列表.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: SQL生成连续列表
author: xxzuo
tags:
- doris
- sql
- hive
categories:
- SQL相关
date: 2024-03-21 20:50:33
---
有时候 需要根据 给定的 开始数据 和 结束数据,生成一段连续序列
比如 给定 开始日期 和 结束日期 生成 连续日期列表。
又或者 给定 开始数字 和 结束数字 生成连续数字列表
就像这样
```
start_date: 2024-01-01
end_date: 2024-01-10
res:
2024-01-01
2024-01-02
2024-01-03
2024-01-04
2024-01-05
2024-01-06
2024-01-07
2024-01-08
2024-01-09
2024-01-10
```

这里 一般只需要处理三个地方
- 计算 开始值 和 结束值 的 差值
- 根据 差值 生成连续序列
- 把 开始值 加上 连续序列的值

这里 以 doris 和 hive 来举例
### Doris生成连续日期

生成 `2024-01-01``2024-01-10`的连续日期序列

- 使用 `datediff`计算差值
[DATEDIFF - Apache Doris](https://doris.apache.org/zh-CN/docs/sql-manual/sql-functions/date-time-functions/datediff/)
```
select datediff('2024-01-10', '2024-01-01')
```

- 利用 explode_number 生成连续序列
[EXPLODE_NUMBERS - Apache Doris](https://doris.apache.org/zh-CN/docs/sql-manual/sql-functions/table-functions/explode-numbers/)
```
select e1
from (select '2024-01-01' k1) as t lateral view explode_numbers(datediff('2024-01-10', '2024-01-01')) tmp1 as e1;
```

- 开始值 加上 连续序列
[DAYS_ADD - Apache Doris](https://doris.apache.org/zh-CN/docs/sql-manual/sql-functions/date-time-functions/days-add/)
```
select e1, k1, to_date(days_add(k1, e1))
from (select '2024-01-01' k1) as t lateral view explode_numbers(datediff('2024-01-10', '2024-01-01') + 1) tmp1 as e1;
```


75 changes: 75 additions & 0 deletions source/_posts/SQL相关/开窗函数-排名.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: 开窗函数-排名
author: xxzuo
tags:
- sql
categories:
- SQL相关
date: 2024-02-03 23:42:33
---

排名主要利用三种函数

- **rank()   排序相同时重复,总数不会减少**

- **dense_rank()    排序相同时重复,总数减少**

- **row_number()  排序不重复,总数不变**

比如对如下表根据分数进行降序排名

|id|grade|
|---|---|
|1|97|
|2|96|
|3|95|
|4|95|
|5|98|
|6|94|

**rank()**  

|id|grade|rank|
|---|---|---|
|5|98|1|
|1|97|2|
|2|96|3|
|3|95|4|
|4|95|4|
|6|94|6|

```sql
select id, grade, rank() over(order by grade) as rank from data_table
```


**dense_rank()** 

|id|grade|rank|
|---|---|---|
|5|98|1|
|1|97|2|
|2|96|3|
|3|95|4|
|4|95|4|
|6|94|5|

```sql
select id, grade, dense_rank() over(order by grade) as rank from data_table
```


**row_number()**

|id|grade|rank|
|---|---|---|
|5|98|1|
|1|97|2|
|2|96|3|
|3|95|4|
|4|95|5|
|6|94|6|

```sql
select id, grade, row_number() over(order by grade) as rank from data_table
```
Loading

0 comments on commit 42ad330

Please sign in to comment.