在 Microsoft SQL 服务器中以正确安排或连续的方式处理此分配以获取日期的正确方法是什么
What would be the proper method to approach this assignment to get the Date in the proper arranged or consecutive manner in Microsoft SQL server
- 首先,数据库是一个普通的单行数据库,但我们必须在创建时查询以将其获取到赋值部分:
- 作业是按照这种格式安排提供日期的任务
为工作流创建时间表
- 动机是按照这种格式排列它们
我完全没有头绪,但已经尝试了 group by 的一些事情,并且都对任何答案持开放态度
抱歉,新来的,请帮忙谢谢!`
CREATE DATABASE project ;
CREATE TABLE project_phases(
project_id int,
phase varchar(200),
start_date date
);
INSERT INTO project_phases (project_id,phase,start_date)
VALUES (1, 'design', '2021-01-01');
INSERT INTO project_phases (project_id,phase,start_date)
VALUES (1, 'development', '2021-01-02');
INSERT INTO project_phases (project_id,phase,start_date)
VALUES (1, 'deployment', '2021-01-03');`
似乎 window 函数 lead() over()
很适合这里
Select project_id
,from_phase = phase
,to_phase = lead(phase,1) over (partition by project_id order by start_date)
,start_date
,end_date = lead(start_date,1) over (partition by project_id order by start_date)
from project_phases
结果
- 首先,数据库是一个普通的单行数据库,但我们必须在创建时查询以将其获取到赋值部分:
- 作业是按照这种格式安排提供日期的任务 为工作流创建时间表
- 动机是按照这种格式排列它们
我完全没有头绪,但已经尝试了 group by 的一些事情,并且都对任何答案持开放态度
抱歉,新来的,请帮忙谢谢!`
CREATE DATABASE project ;
CREATE TABLE project_phases(
project_id int,
phase varchar(200),
start_date date
);
INSERT INTO project_phases (project_id,phase,start_date)
VALUES (1, 'design', '2021-01-01');
INSERT INTO project_phases (project_id,phase,start_date)
VALUES (1, 'development', '2021-01-02');
INSERT INTO project_phases (project_id,phase,start_date)
VALUES (1, 'deployment', '2021-01-03');`
似乎 window 函数 lead() over()
很适合这里
Select project_id
,from_phase = phase
,to_phase = lead(phase,1) over (partition by project_id order by start_date)
,start_date
,end_date = lead(start_date,1) over (partition by project_id order by start_date)
from project_phases
结果