说我有两个表(颜色,水果),其中包含以下列(黄色,橙色,苹果,桌子,sky1,sky2,sky3 .. sky15)。
我进行了查询
SELECT Color.yellow AS Yellow, Fruit.orange AS Orange, Color.sky*
FROM Color
LEFT JOIN Fruit ON Color.Yellow = Fruit.orange
获取所有sky *列。 但是,当然,它没有用。
如何在不键入全部sky *列的情况下获取全部sky *列?
答案 0 :(得分:0)
为减轻您的痛苦,我建议采取一种小补救措施:
select string_agg('sky' || i, ', ') from generate_series(1,100) as i;
string_agg
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
sky1, sky2, sky3, sky4, sky5, sky6, sky7, sky8, sky9, sky10, sky11, sky12, sky13, sky14, sky15, sky16, sky17, sky18, sky19, sky20, sky21, sky22, sky23, sky24, sky25, sky26, sky27, sky28, sky29
, sky30, sky31, sky32, sky33, sky34, sky35, sky36, sky37, sky38, sky39, sky40, sky41, sky42, sky43, sky44, sky45, sky46, sky47, sky48, sky49, sky50, sky51, sky52, sky53, sky54, sky55, sky56, sk
y57, sky58, sky59, sky60, sky61, sky62, sky63, sky64, sky65, sky66, sky67, sky68, sky69, sky70, sky71, sky72, sky73, sky74, sky75, sky76, sky77, sky78, sky79, sky80, sky81, sky82, sky83, sky84,
sky85, sky86, sky87, sky88, sky89, sky90, sky91, sky92, sky93, sky94, sky95, sky96, sky97, sky98, sky99, sky100
(1 row)
#