Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. find average of not null records

find average of not null records

Scheduled Pinned Locked Moved Database
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raghvendrapanda
    wrote on last edited by
    #1

    Hy, Is there any function through which i can find the average of the not null rows only.Like total/number of rows containg data Thankz & Ragards , raghvendra Panda

    R T 2 Replies Last reply
    0
    • R raghvendrapanda

      Hy, Is there any function through which i can find the average of the not null rows only.Like total/number of rows containg data Thankz & Ragards , raghvendra Panda

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      Why would you store rows that have no data? In any case maybe what you are asking is how, for instance, do I get all records where one field is not null?

      select count(*) from table where not column3 is null

      might be close to what you want.

      me, me, me "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven

      1 Reply Last reply
      0
      • R raghvendrapanda

        Hy, Is there any function through which i can find the average of the not null rows only.Like total/number of rows containg data Thankz & Ragards , raghvendra Panda

        T Offline
        T Offline
        thatraja
        wrote on last edited by
        #3

        I hope it will help you. NORTHWIND Database

        SELECT
        COUNT(UnitPrice) AS [NoOfItems], SUM(UnitPrice) AS [TOTAL], AVG(UnitPrice) AS [AVERAGE]
        FROM Products
        WHERE UnitPrice IS NOT NULL

        OUTPUT

        NoOfItems TOTAL AVERAGE


        77 2222.71 28.8663

        thatraja


        Tips/Tricks|Brainbench certifications

        R P 2 Replies Last reply
        0
        • T thatraja

          I hope it will help you. NORTHWIND Database

          SELECT
          COUNT(UnitPrice) AS [NoOfItems], SUM(UnitPrice) AS [TOTAL], AVG(UnitPrice) AS [AVERAGE]
          FROM Products
          WHERE UnitPrice IS NOT NULL

          OUTPUT

          NoOfItems TOTAL AVERAGE


          77 2222.71 28.8663

          thatraja


          Tips/Tricks|Brainbench certifications

          R Offline
          R Offline
          raghvendrapanda
          wrote on last edited by
          #4

          Thnks for ur reply I had taken avg(isnull(column),0)..is that the reason why my function is also considering null rows also?

          C 1 Reply Last reply
          0
          • R raghvendrapanda

            Thnks for ur reply I had taken avg(isnull(column),0)..is that the reason why my function is also considering null rows also?

            C Offline
            C Offline
            Chris Meech
            wrote on last edited by
            #5

            raghvendrapanda wrote:

            avg(isnull(column),0)..

            The answer is yes, but as a test why don't you try the following.

            avg(isnull(column),42) ..

            :)

            Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

            L 1 Reply Last reply
            0
            • C Chris Meech

              raghvendrapanda wrote:

              avg(isnull(column),0)..

              The answer is yes, but as a test why don't you try the following.

              avg(isnull(column),42) ..

              :)

              Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              I see, the "average" function needs to be calibrated first. :laugh:

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Getting an article published on CodeProject should be easier and faster.


              C 1 Reply Last reply
              0
              • L Luc Pattyn

                I see, the "average" function needs to be calibrated first. :laugh:

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Getting an article published on CodeProject should be easier and faster.


                C Offline
                C Offline
                Chris Meech
                wrote on last edited by
                #7

                Just like the random function needs to be seeded. :-D

                Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

                1 Reply Last reply
                0
                • T thatraja

                  I hope it will help you. NORTHWIND Database

                  SELECT
                  COUNT(UnitPrice) AS [NoOfItems], SUM(UnitPrice) AS [TOTAL], AVG(UnitPrice) AS [AVERAGE]
                  FROM Products
                  WHERE UnitPrice IS NOT NULL

                  OUTPUT

                  NoOfItems TOTAL AVERAGE


                  77 2222.71 28.8663

                  thatraja


                  Tips/Tricks|Brainbench certifications

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  I'm not sure that the WHERE UnitPrice IS NOT NULL is required here -- COUNT(UnitPrice) will only count the non-null entries anyway, right? Same with SUM and AVG?

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups