将一个查询的X量结果附加到另一个查询的X量结果(没有外键连接)

时间:2013-05-09 13:35:24

标签: sql postgresql

此查询会返回如下结果:select distinct date from dwh.product_count

April, 2013
March, 2013
February, 2013
January, 2013

我想追加许多结果^ ^会带回此查询的结果:

select distinct p_id dwh.members a

5
7
8
...etc

所以我的结果看起来像这样:

5    April, 2013
5    March, 2013
5    February, 2013
5    January, 2013
7    April, 2013
7    March, 2013
7    February, 2013
7    January, 2013
etc....

什么类型的查询会带来这些结果?

2 个答案:

答案 0 :(得分:2)

select id, dt
from 
    (select distinct p_id as id from dwh.members) s
    cross join
    (select distinct date as dt from dwh.product_count) t

答案 1 :(得分:1)

select id, dt from 
( select distinct p_id as id from dwh.members )
.( select distinct date as dt from dwh.product_count )