Grouping Count

  • Hi All,

    I have domain in Column A. Here I need to count how many domain and need them to flag 1, 2, 3 and so on till maximum. How could I do them in SQL Server. Please find the attachment excel file for reference.

    Thanks

    Attachments:
    You must be logged in to view attached files.
  • Forum members here will not download files because of possible infections/viruses.

    Provide DDL with some sample data with required output.

    =======================================================================

  • I'm actually not too concerned about opening xlsx files, as they can't contain executable code (as far as I know). I downloaded and virus-scanned this one before I opened it.

    Is this the sort of thing you were looking for?

    DROP TABLE IF EXISTS #Domain;

    CREATE TABLE #Domain
    (
    Domain VARCHAR(100) NOT NULL
    );

    INSERT #Domain
    (
    Domain
    )
    VALUES
    ('.uchicago.edu')
    ,('012.net.il')
    ,('012.net.il')
    ,('012.net.il')
    ,('013net.net');

    SELECT d.Domain
    ,Counts = ROW_NUMBER () OVER (PARTITION BY d.Domain ORDER BY d.Domain)
    FROM #Domain d;

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Phil Parkin wrote:

    I'm actually not too concerned about opening xlsx files, as they can't contain executable code (as far as I know). I downloaded and virus-scanned this one before I opened it.

    People need to understand that a lot of us don't want to post code solutions without testing them.  While I agree that it's fairly trivial for us to convert test data from a spreadsheet to readily consumable data to do such a test, the OP did get the data from somewhere... probably a database.  While they're there and, since it is relatively trivial, THEY can provide the test data in readily consumable format.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This was removed by the editor as SPAM

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply