怎么替换?专栏?来自子查询输出

时间:2012-09-05 14:23:00

标签: postgresql select subquery

如何将名称放在子查询的输出上,而不是?column?

SELECT的输出是:

._______.__________.__________.
|__id___|_?column?_|_?column?_|
|_31886_|____12____|____13____|

我想要的是:

._______.__________.__________.
|__id___|___ages___|_validate_|
|_31886_|____12____|____13____|

SELECT的样子:

SELECT g.id,
(select dt from pcdhidro where nomepcd=31886 order by datahora asc limit 1),
(select dt from pcdhidro_2003_96 where nomepcd=31886)
FROM gestpcd_2 g
WHERE g.tipo = 'HIDRO' and g.id = 31886

1 个答案:

答案 0 :(得分:1)

(Select X from Y) AS alias

所以在你的情况下:

SELECT g.id,
(select dt from pcdhidro where nomepcd=31886 order by datahora asc limit 1) as ages,
(select dt from pcdhidro_2003_96 where nomepcd=31886) as validate
FROM gestpcd_2 g
WHERE g.tipo = 'HIDRO' and g.id = 31886