SQL Query

  • Current table

    ColA ColB ColC

    A 1 Yes

    A 2 No

    A 1 Yes

    A 1 Yes

    B 1 Yes

    B 2 Yes

    C 1 Yes

    D 1 No

    My result should be

    A No

    B Yes

    C No

    If ColA Values A,B or C have a No under ColC then result is No else Yes

    How can I get this with a SQL query?

    Thanks

  • smmkr17 (12/5/2015)


    Current table

    ColA ColB ColC

    A 1 Yes

    A 2 No

    A 1 Yes

    A 1 Yes

    B 1 Yes

    B 2 Yes

    C 1 Yes

    D 1 No

    My result should be

    A No

    B Yes

    C No

    If ColA Values A,B or C have a No under ColC then result is No else Yes

    How can I get this with a SQL query?

    Thanks

    If those are the only two possible values in ColC, then the solution is easy...

    SELECT ColA

    ,ColC = MIN(ColC)

    FROM dbo.SomeTable

    GROUP BY ColA

    ;

    --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)

  • smmkr17 (12/5/2015)


    Current table

    ColA ColB ColC

    A 1 Yes

    A 2 No

    A 1 Yes

    A 1 Yes

    B 1 Yes

    B 2 Yes

    C 1 Yes

    D 1 No

    My result should be

    A No

    B Yes

    C No

    If ColA Values A,B or C have a No under ColC then result is No else Yes

    How can I get this with a SQL query?

    Thanks

    Given those rules, shouldn't C be a 'yes' ?

  • patrickmcginnis59 10839 (12/8/2015)


    smmkr17 (12/5/2015)


    Current table

    ColA ColB ColC

    A 1 Yes

    A 2 No

    A 1 Yes

    A 1 Yes

    B 1 Yes

    B 2 Yes

    C 1 Yes

    D 1 No

    My result should be

    A No

    B Yes

    C No

    If ColA Values A,B or C have a No under ColC then result is No else Yes

    How can I get this with a SQL query?

    Thanks

    Given those rules, shouldn't C be a 'yes' ?

    Probably D should be C in the last row. Or there's something missing.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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