Count the number of records of my IF

0

IF (count (UCID)> 1, count (UCID), '0') , it brings me approximately 500 record lines, being numbers 2 above, I want to be able to do a COUNT in that IF to display those 500's in a separate column. Anyone have a suggestion? Thanks in advance.

Thecolumn"Recall" is my IF and it is there with 10 result lines, I want to know how to show the result 10 (column "QTD of Records") in another column.

    
asked by anonymous 06.06.2017 / 20:23

1 answer

1

Get your query, let's call it Q_ORIGINAL . Declare it in a CTE .

To get accustomed to CTEs, it's an alternative to subqueries that I find very elegant. Let's start from here, which gets exactly the same answer as Q_ORIGINAL :

WITH q AS (
    Q_ORIGINAL
)
SELECT
    *
FROM q

With CTEs, we can make some interesting jokes; for example, use CTE that depends on another CTE:

WITH q AS (
    Q_ORIGINAL
), conta_q AS (
    SELECT
        COUNT(*) as n
    FROM
        q
)
SELECT
    *,
    (SELECT n FROM conta_q) as QTD
FROM
    q

Note that this will add a new column with the quantity for all result rows.

    
06.06.2017 / 21:02