我不确定这是否可行,但是...我有Oracle DB中一个表的名称列表
Select Staff_Name
From Staff_List
然后我想要创建一个日历并将其加入,以便每个名称都出现在A列中,而当年的日期则出现在B列中。因此,每个名称在A列中都会出现365次,对于每年B栏中的每一天。
我不知道如何...
答案 0 :(得分:1)
尝试一下:
select staff_name, dt from staff_list
cross join (select (TRUNC(SYSDATE,'YEAR')-1) + level as dt from dual connect by level <= ADD_MONTHS(TRUNC(SYSDATE,'YEAR'),12)-TRUNC(SYSDATE,'YEAR'))
答案 1 :(得分:1)
对于当前年份(因为并非每年都有365天,对吗?):
SQL> with
2 staff_list (staff_name) as
3 (select 'Little' from dual union all
4 select 'Foot' from dual
5 ),
6 calendar (c_date) as
7 (select trunc(sysdate, 'yyyy') + level - 1
8 from dual
9 connect by level <= add_months(trunc(sysdate, 'yyyy'), 12) - trunc(sysdate, 'yyyy')
10 )
11 select s.staff_name, c.c_date
12 from staff_list s cross join calendar c
13 order by c.c_date, s.staff_name;
STAFF_ C_DATE
------ ----------
Foot 01.01.2019
Little 01.01.2019
Foot 02.01.2019
Little 02.01.2019
Foot 03.01.2019
Little 03.01.2019
Foot 04.01.2019
Little 04.01.2019
Foot 05.01.2019
Little 05.01.2019
snip
Foot 30.12.2019
Little 30.12.2019
Foot 31.12.2019
Little 31.12.2019
730 rows selected.
SQL>