我尝试为列challenge_name设置别名,尤其是遇到基于时间戳/日期的“challenge”(如challenge 1、challenge 2等)时。如果不是“challenge”,我希望将列名设置为与challenge_name相同
这是我目前的输入
+-----------+----------------+
| date | challenge_name |
+-----------+----------------+
| 1/11/2022 | find the bug |
| 1/12/2022 | challenge |
| 1/13/2022 | kill pill |
| 1/14/2022 | hello copter |
| 1/15/2022 | challenge |
| 1/16/2022 | miami |
| 1/17/2022 | hello world |
| 1/18/2022 | challenge |
| 1/19/2022 | dominc |
| 1/20/2022 | challenge |
+-----------+----------------+
这是我的预期输出
+-----------+----------------+--------------+
| date | challenge_name | updated_name |
+-----------+----------------+--------------+
| 1/11/2022 | find the bug | find the bug |
| 1/12/2022 | challenge | challenge 1 |
| 1/13/2022 | kill pill | kill pill |
| 1/14/2022 | hello copter | hello copter |
| 1/15/2022 | challenge | challenge 2 |
| 1/16/2022 | miami | miami |
| 1/17/2022 | hello world | hello world |
| 1/18/2022 | challenge | challenge 3 |
| 1/19/2022 | dominc | dominc |
| 1/20/2022 | challenge | challenge 4 |
+-----------+----------------+--------------+
2条答案
按热度按时间cwdobuhd1#
Rank将为每个特定的challenge_name组分配一个等级,我没有只过滤掉challenge_name = challenge时的值,因为它们是根据case条件过滤的
https://dbfiddle.uk/oRJ0bQh7
7cwmlq892#
以下方法可能有效:
编辑
在窗口函数中添加了order by子句