从同一个表的多个实例中获取不同的值

时间:2015-01-14 19:10:34

标签: sql postgresql

我正在尝试使用该表的多个实例从表中提取不同的值,因此我只返回不同的值。

我正在尝试为表中的每个条目提取不同的contract_id。有多个条目具有相同的contract_id。一旦我有了,我就会尝试将所有条目contract_id's放在同一行。

SELECT DISTINCT
  (a.inspection_id) AS inspection_id,
  (a.contract_id, b.contract_id, c.contract_id) AS Contract_id,
  b.linking_id AS inspector_id,
  c.string_value AS phone
FROM inspection a, inspection b, inspection c
WHERE a.contract_id = b.contract_id
  and a.contract_id = b.contract_id
  and a.contract_id = c.contract_id
  and a.position = 0
  and b.position = 1
  and c.position = 2;

我返回的所有内容都是空输出,但我知道,表中有值。

0 个答案:

没有答案
相关问题