Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DB2查询将月数从1到12作为12行_Db2 - Fatal编程技术网

DB2查询将月数从1到12作为12行

DB2查询将月数从1到12作为12行,db2,Db2,DB2查询将月数从1到12作为12行 我希望结果如下 1. 2. 3. 4. 5. 6. 7. 8. 9 10 11 12 请务必让我知道您的想法。WITH子句允许您定义要从中选择的表。可以执行以下操作: with dummy(id) as ( select 1 from SYSIBM.SYSDUMMY1 union all select id + 1 from dummy where id < 12 ) select id from dummy 我假设您

DB2查询将月数从1到12作为12行

我希望结果如下

1. 2. 3. 4. 5. 6. 7. 8. 9 10 11 12 请务必让我知道您的想法。

WITH子句允许您定义要从中选择的表。可以执行以下操作:

with dummy(id) as (
    select 1 from SYSIBM.SYSDUMMY1    
    union all
    select id + 1 from dummy where id < 12
)
select id from dummy

我假设您在所有模式的所有表中有+12列,您可以这样做:

select rownumber() over() as mymonth from syscolumns
fetch first 12 rows only
其他方法:

with AllMonth(mymonth) as (
    values (1), (2), (3), (4),(5), (6),(7), (8), (9), (10),(11), (12)
)
select mymonth from AllMonth
with AllMonth(mymonth) as (
Select 1 from SYSIBM.SYSDUMMY1 
union all
Select 2 from SYSIBM.SYSDUMMY1 
union all
Select 3 from SYSIBM.SYSDUMMY1 
union all
Select 4 from SYSIBM.SYSDUMMY1 
union all
Select 5 from SYSIBM.SYSDUMMY1 
union all
Select 6 from SYSIBM.SYSDUMMY1 
union all
Select 7 from SYSIBM.SYSDUMMY1 
union all
Select 8 from SYSIBM.SYSDUMMY1 
union all
Select 9 from SYSIBM.SYSDUMMY1 
union all
Select 10 from SYSIBM.SYSDUMMY1 
union all
Select 11 from SYSIBM.SYSDUMMY1 
union all
Select 12 from SYSIBM.SYSDUMMY1 
)
select mymonth from AllMonth
或不带:

select mymonth from (
values (1), (2), (3), (4),(5), (6),(7), (8), (9), (10),(11), (12)
) AllMonth(mymonth)
其他方法:

with AllMonth(mymonth) as (
    values (1), (2), (3), (4),(5), (6),(7), (8), (9), (10),(11), (12)
)
select mymonth from AllMonth
with AllMonth(mymonth) as (
Select 1 from SYSIBM.SYSDUMMY1 
union all
Select 2 from SYSIBM.SYSDUMMY1 
union all
Select 3 from SYSIBM.SYSDUMMY1 
union all
Select 4 from SYSIBM.SYSDUMMY1 
union all
Select 5 from SYSIBM.SYSDUMMY1 
union all
Select 6 from SYSIBM.SYSDUMMY1 
union all
Select 7 from SYSIBM.SYSDUMMY1 
union all
Select 8 from SYSIBM.SYSDUMMY1 
union all
Select 9 from SYSIBM.SYSDUMMY1 
union all
Select 10 from SYSIBM.SYSDUMMY1 
union all
Select 11 from SYSIBM.SYSDUMMY1 
union all
Select 12 from SYSIBM.SYSDUMMY1 
)
select mymonth from AllMonth

您是如何开始的,您的SELECT语句是什么?你研究过WITH子句吗?WITH子句使用一个表进行迭代,但我没有任何表进行迭代,我只需要从1到12的12行值。动态定义表!