Quiz: AVG() in TSQL

Before we begin…

The code samples in this quiz use a table value constructor to make the code samples easily portable. The table value constructor makes a 2 row table, which looks like this:

Quiz: AVG()

  • SELECT AVG(t.avgme) AS val
    FROM (VALUES
         (1),
         (1)) as t(avgme);
  • SELECT AVG(t.avgme) AS val
    FROM (VALUES
         (1),
         (2)) as t(avgme);
  • SELECT CAST (
             AVG(t.avgme)
         AS NUMERIC(3,1)
         ) AS val
    FROM (VALUES
         (1),
         (2)) as t(avgme);
  • SELECT AVG (
            CAST( t.avgme AS NUMERIC(3,1) )
        ) AS val
    FROM (VALUES
         (1),
         (2)) as t(avgme);

Want to learn more?

Check out the documentation on AVG, or join the SQL Symposium to get in on TSQL School!

2 thoughts on “Quiz: AVG() in TSQL

  1. Hi Kendra,
    Are you planning to include explanations to the answers in this test? Even though I reviewed the MS docs on AVG, some correct options are still unclear. Thanks for the test!

    1. I am working on a blog post to go live tomorrow to talk through the problems. Will add a link on this quiz to the post as soon as it goes live.

      Glad you enjoyed it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.