Count the amount of my IF records

Asked

Viewed 418 times

0

IF(Count(UCID)>1,Count(UCID),'0'), it brings me approximately 500 lines of record, being numbers of 2 above, I want to be able to make a COUNT in that IF to present those 500 in a column to part. Does anyone have a suggestion? Thank you in advance. inserir a descrição da imagem aqui

the column "Rechamada" is my IF and this one with 10 result lines, I want to know how to show in another column the result 10 (column "QTD of Records").

  • I didn’t understand your problem. Could you show an example of how your desired output would be?

  • 1

    @Jeffersonquesado edited placing an image see if it helps understanding.

  • Um, I opened the image on the phone, but now I can’t... Anyway, I can’t think of any more elegant way, but I have a proposal...

  • would be like an excel conta.values but in SQL, something equivalent.

1 answer

1

Take your appointment, let’s call it Q_ORIGINAL. Declare her in a CTE.

To get used to Ctes, it is an alternative to Subqueries that I find very elegant. Let’s start from here, which gets exactly the same answer as the Q_ORIGINAL:

WITH q AS (
    Q_ORIGINAL
)
SELECT
    *
FROM q

With Ctes, we can do some interesting games; 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 amount for all result lines.

  • 1

    Very well thought out face, however, it is much more difficult to do here, because I am in a B.I software where my IF is an expression, a line, a small calculation stretch, I thought it was simpler as "Count(if(Count(ucid)..." but I think it will not roll.

  • It’s a shame it didn’t work... I couldn’t think of another strategy that would solve

Browser other questions tagged

You are not signed in. Login or sign up in order to post.