别名POSTGRES选择语句

时间:2017-01-28 14:14:10

标签: sql postgresql

我想在查询中创建新表,并在最后使用它们进行最终查询。我不记得语法是什么,无法在任何地方找到它。 (这里只是一个基本的例子)。

phones as 
    (
        SELECT phone_number from customers
    )


emails as 
    (
        SELECT emails from customers
    )

// do something with both

2 个答案:

答案 0 :(得分:6)

您正在寻找with phones as ( SELECT phone_number from customers ), emails as ( SELECT emails from customers ) select . . .;

CTE's

答案 1 :(得分:2)

您正在寻找通用表格表达式(CTE)。这些是使用public void takePhoto() { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); File folder = new File(Environment.getExternalStorageDirectory() + "/PhotoBox"); if (!folder.exists()) { folder.mkdir(); } final Calendar c = Calendar.getInstance(); String new_Date = c.get(Calendar.DAY_OF_MONTH) + "-" + ((c.get(Calendar.MONTH)) + 1) + "-" + c.get(Calendar.YEAR) + " " + c.get(Calendar.HOUR) + "-" + c.get(Calendar.MINUTE) + "-" + c.get(Calendar.SECOND); path = String.format(Environment.getExternalStorageDirectory() + "/" + "PhotoBox" + "/%s.png", "Product(" + new_Date + ")"); File photo = new File(path); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); xPath = path; startActivityForResult(intent, 2); }

引入的
with

您的示例选择似乎并不特别有用,但我认为它们仅用于说明。