query like count(name),name,surname

  • I need query like

    select count(name),name,surname from info

    table info has only three columns

    id int,

    name varchar,

    surname varchar

  • select count(*), name, surname

    from TableName

    group by name, surname

  • ok.

    But I do not need row count i need count(name).

    eg.

    count(name) name surname

    --------------------------------

    1 may jar

    2 may kar

    3 may sar

    4 apl ril

    5 apl rol

    then result should be

    count(name) name surname

    -----------------------------------

    3 may jar

    3 may kar

    3 may sar

    2 apl ril

    2 apl rol

  • SELECT

    COUNT(*) OVER (PARTITION BY name), name, surname

    FROM

    Info

  • select name, surname, (select count(*) from Info where name=a.name) as countname

    from Info a

    "Don't limit your challenges, challenge your limits"

  • mjarsaniya (5/19/2009)


    ok.

    But I do not need row count i need count(name).

    eg.

    count(name) name surname

    --------------------------------

    1 may jar

    2 may kar

    3 may sar

    4 apl ril

    5 apl rol

    then result should be

    count(name) name surname

    -----------------------------------

    3 may jar

    3 may kar

    3 may sar

    2 apl ril

    2 apl rol

    This is why giving example input and output in the original question is a good idea!

    Peter has the answer for you

  • Thanks,

    kruti, Peter Brinkhaus

    your both's reply works and i get solution thanks............

Viewing 7 posts - 1 through 6 (of 6 total)

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