custome query.

  • Hi

    I have a table results with

    CompanyTeam Status

    WiproGroup1Finished

    TCSGroup1 Solved

    WiproGroup2Solved

    GEGROUP2Finished

    TCSGroup1Not solved

    SatyamGroup3Not solved

    I need results ouptlike

    group1group2 group3

    com count(com) solved finished not solvedsolved finished notsolved solved finished notsolved

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

    Wipro201 0100 0 00

    TCS210 1000 0 00

    GE100 001 0 0 00

    Satyam100 000 0 0 0 0

    Can any one please ..

    Thanks

  • Sharon Kumar (3/4/2011)


    Hi

    I have a table results with

    CompanyTeamStatus

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

    Wiprogroup1finished

    TCSgroup1Solved

    Wiprogroup2solved

    GEgroup2finished

    TCSgroup1not solved

    Satyamgroup3not solved

    I need results ouptlike

    group1group2 group3

    com count(com) solved finished not solvedsolved finished notsolved solved finished notsolved

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

    Wipro201 0100 0 00

    TCS210 1000 0 00

    GE100 001 0 0 00

    Satyam100 000 0 0 0 0

    Can any one please ..

    Thanks

    Try something like this:

    create table TeamData(

    company varchar(10)

    ,groupId varchar(10)

    ,statusFlag varchar(10)

    )

    go

    insert into TeamData (company, groupId, statusFlag) values ('Wipro','group1','finished')

    go

    insert into TeamData (company, groupId, statusFlag) values ('TCS','group1','solved')

    go

    insert into TeamData (company, groupId, statusFlag) values ('Wipro','group2','solved')

    go

    insert into TeamData (company, groupId, statusFlag) values ('GE','group2','finished')

    go

    insert into TeamData (company, groupId, statusFlag) values ('TCS','group1','not solved')

    go

    insert into TeamData (company, groupId, statusFlag) values ('Satyam','group3','not solved')

    go

    select company, groupid, finished, solved, [not solved]

    from

    (select company, groupid, statusFlag

    from TeamData) t

    pivot (count(statusFlag) for statusFlag in ([finished],[solved],[not solved])) p

    -Ki

    -Ki

  • Thanks a very much dude...

  • Happy to help.

    -Ki

    -Ki

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

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