query help

  • ssis learner__ (7/14/2010)


    ... I dont really trust left joins ...

    :w00t:

    Me too! I hate them! They are commie bustards!

    Vote conservatives! :-D:-D:-D

    You wanted to say: "I don't really understand how left joins work".

    Which most likely means you don't understand how any JOINs work.

    You better to learn them, otherwise you will always struggle coding in T-SQL. There are a lot of sources of information which can help you, try this one for example:

    http://www.w3schools.com/Sql/sql_join.asp

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • No left join is needed for this so I wouldn't use one either.

    ;WITH cteTemp

    AS

    (

    select [EMP],

    [order_no],

    EmpAccts = DENSE_RANK() OVER (PARTITION BY [EMP] ORDER BY [order_no]),

    EmpRes = ROW_NUMBER() OVER (PARTITION BY [order_no] ORDER BY [counter] DESC)

    from [dbo].[abcd]

    )

    SELECT [EMP],

    MAX(EmpAccts) as No_of_accounts,

    ISNULL(SUM(CASE WHEN EmpRes = 1 THEN 1 END),0) as resolutioncount

    FROM cteTemp

    GROUP BY [EMP]

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • bteraberry (7/14/2010)


    No left join is needed for this so I wouldn't use one either.

    ...

    One thing is when LEFT JOIN is not needed. Not trusting to LEFT JOIN (due to political or class affiliation :-D) is absolutely other thing (from diffferent opera) ...

    Do you trust to INNER JOIN more than to LEFT JOIN?

    What about RIGHT JOIN?

    Are FULL and CROSS JOINS "political prostitutes", so you don't trust them either?

    Do you trust in BIGINT but not in INT due to class-war thing?

    Do you hate liars and therefore never set BOOLEAN variables to FALSE - always keep them as TRUE?

    :w00t::w00t::w00t:

    :-D:-D:-D

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • @Bt...........

    OMG ..........!!!!!!!!!!!!!!

    This is an unbelievable code man..... You must be a GGGenius........

    Thank you so much for the help. ...

    I just ran this code and got the exact results....

    now let me research about the code and the function you used in it...DENSE_RANK() ,as I have never used this before.........

    Thanks again...

    [font="Comic Sans MS"]
    ---------------------------------------------------

    Thanks [/font]

  • @Eugene Elutin,

    IGNORED..........................

    [font="Comic Sans MS"]
    ---------------------------------------------------

    Thanks [/font]

Viewing 5 posts - 16 through 19 (of 19 total)

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