简体   繁体   English

别名POSTGRES select语句

[英]Alias a POSTGRES select statement

I want to create new tables in the query and use them at the end for a final query. 我想在查询中创建新表,并在最后使用它们进行最终查询。 I don't remember what the syntax is and can't find it anywhere. 我不记得语法是什么,在任何地方都找不到。 (here is a basic example for illustration only). (这是一个基本示例,仅用于说明)。

phones as 
    (
        SELECT phone_number from customers
    )


emails as 
    (
        SELECT emails from customers
    )

// do something with both

You are looking for CTE's 您正在寻找CTE's

With phones as 
    (
        SELECT phone_number from customers
    )
,emails as 
    (
        SELECT emails from customers
    )
select * from phones--/emails 

You are looking for a Common Table Expression (CTE). 您正在寻找通用表表达式(CTE)。 These are introduced using with : 这些使用介绍with

with phones as (
      SELECT phone_number from customers
     ),
     emails as (
      SELECT emails from customers
    )
select . . .;

Your example selects don't seem particularly useful, but I assume they are just for illustration. 您的示例选择似乎并不特别有用,但我认为它们仅用于说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM