2012-09-05 38 views
0

如何將名稱放在子查詢的輸出上,而不是?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
(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 
+0

它解決了謝謝:) –