Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 207

Common Table Expression syntax

$
0
0

Considering a query with CTEs:

WITH cte_0 AS (          SELECT SUM(col_0)          FROM table_0          WHERE condition_00          AND condition_01    ),     cte_1 AS (          SELECT SUM(col_1)          FROM table_0          WHERE condition_10          AND condition_11    )    SELECT (          ((SELECT * FROM cte_0) * 100) / (SELECT * FROM cte_1),          ((SELECT * FROM cte_0) + 100) * (SELECT * FORM cte_1)    ) FROM cte_0, cte_1

Would it be correct to leave the last FROM out? And do I get a tuple of two numbers with a query like that? Or do I need a new table from which I SELECT * to get two numbers?

I just started my first PostgreSQL project and I've seen different styles of writing it. All comments on the style are warmly welcomed. I have not found any suitable online PostgreSQL platform for testing queries. Are there any?

Question edited to include conditions and a more complicated result.


Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>