Group By, Count, and NULLs

  • Comments posted to this topic are about the item Group By, Count, and NULLs

  • Maybe tomorrow QoTD will be:

    COUNT(*) AS MyCount

    And MyCount value will be 2 in this case (*) for the Null rows 😛

  • Easy Question.

  • Hany Helmy (2/1/2015)


    Maybe tomorrow QoTD will be:

    COUNT(*) AS MyCount

    And MyCount value will be 2 in this case (*) for the Null rows 😛

    +1

    Or, using field "Mychar" in the aggregate function instead of MyId

    To Author: Thank you for the post, really good one and I liked the twist of logic happening in my head. 😎

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • Good to know that group by lumps the nulls.

    Thanks

    Igor Micev,
    My blog: www.igormicev.com

  • This was removed by the editor as SPAM

  • Great question, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks for the question. We've had a bunch of these COUNT questions lately.

  • Hany Helmy (2/1/2015)


    Maybe tomorrow QoTD will be:

    COUNT(*) AS MyCount

    And MyCount value will be 2 in this case (*) for the Null rows 😛

    Almost got it wrong for *assuming* the count was of the MyChar column. It pays to double-check!

    I thought tomorrow's question might be:

    COUNT(MyChar) AS MyCount

    where MyCount value will also be 2.

  • Why are we getting so many count with null questions recently?

  • Nice question to highlight the differences in ways that NULLs are handled by different operations. Thanks!

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • ZZartin (2/2/2015)


    Why are we getting so many count with null questions recently?

    1. Good review

    2. Helps those less experienced

  • I appreiate the questions lately. I think it's good to know the different ways that functions work, especially when dealing with NULLs. The basics are always good to know - they're the basics. I learned something from the SOME question a few days ago.

  • +1 - thanks for the question.

  • Good Question...

    That's why I prefer using count(1)

    Pramod
    SQL Server DBA | MCSE SQL Server 2012/2014

    in.linkedin.com/in/pramodsingla/
    http://pramodsingla.wordpress.com/

Viewing 15 posts - 1 through 15 (of 19 total)

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