【发布时间】:2014-04-28 11:32:01
【问题描述】:
首先我将描述整个想法。我有一个系统正在存储有关Projects 的信息。每个项目都有很多Topics。每个项目每个月都会进行修订。比如:
2014-01-01 Was added Project '1' in relation of 40 Topics
2014-01-01 Was added Project '2' in relation of 120 Topics
2014-02-01 Was added Project '1' in relation of 30 Topics
2014-02-01 Was added Project '2' in relation of 100 Topics
我想计算主题之间的差异,其中有多少是新的,有多少已经结束,有多少仍在进行中。
我已经按照试过了
创建一个查询。 表结构:
database=> \d project
Tabela "public.project"
Kolumna | Typ | Modyfikatory
----------------+---------+---------------------------------------------------------
id | integer | niepusty domyĹnie nextval('project_id_seq'::regclass)
scid | integer |
starttime | date |
database=> \d topic
Tabela "public.topic"
Kolumna | Typ | Modyfikatory
----------------+---------+-----------------------------------------------------
id | integer | niepusty domyĹnie nextval('topic_id_seq'::regclass)
project _id | integer |
topicengine_id | integer |
parameter | text |
description | text |
severity | text |
requirement_id | integer |
topicparam_id | integer |
我的第一次尝试是使用内部连接计算 on going 主题:
SELECT t1.id
FROM topic t1
INNER JOIN topic t2
ON t1.id = t2.id
INNER JOIN project p1
ON p1.id = t1.project_id
INNER JOIN project p2
ON p2.id = t2.project_id
WHERE p1.id = 1101
AND p2.id = 1168
但是每次结果都是空的。谁能指出我做错了什么?
【问题讨论】:
标签: postgresql join inner-join