I need solution for this problem

  • saravanatn - Saturday, July 28, 2018 11:13 AM

    tvrarundeepak - Saturday, July 28, 2018 10:52 AM

    saravanatn - Saturday, July 28, 2018 10:37 AM

    tvrarundeepak - Saturday, July 28, 2018 10:32 AM

    tvrarundeepak - Saturday, July 28, 2018 10:31 AM

    saravanatn - Saturday, July 28, 2018 10:24 AM

    tvrarundeepak - Saturday, July 28, 2018 10:18 AM

    Hi Saravanan,
    Output should like this
    FirstName     FamilyName    
    Arun                 Don

    Only  you want the below as output:
    FirstName     FamilyName    
    Arun                 Don

    Are you sure?

    yes

    like there is n number of familyname and firstname

    your explanation is not clear. Can you kindly post expected output?

    In the below table we have three family names for example 


    Output should be like this 
    Firstname should be randomly selected for each family.
    Firstname Familyname city
    Mathu        Don              US
    Peri            Chennai        TN
    no               Do                 ys


    Below query should work I think

    SELECT
    MAX(Firstname) over(partition by FamilyName,City order by Firstname) as Firstname,
    FamilyName,City
    FROM dbo.people;
    ----------------------------------------
    SELECT
    MIN(Firstname) over(partition by FamilyName,City order by Firstname) as Firstname,
    FamilyName,City
    FROM dbo.people;

    SELECT
      MAX(Firstname), FamilyName, City
    FROM dbo.people
    GROUP BY FamilyName, City

Viewing post 16 (of 15 total)

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