• Skip to main content
  • Skip to primary sidebar

Datannum

Data science for small business applications

  • Home
  • Microsoft Excel (spreadsheet) forum
    • Project: Analyze NYSE Data
  • SQL forum
    • Project: Query a Digital Music Store Database
  • Tableau forum (data visualization)
    • Project: Data Visualization Project using Tableau
  • Linear Algebra forum
    • Curated resource to learn linear algebra
  • Web development
    • WordPress forum
    • Google Support

Spotting null values using CASE clause

Data Science for Small Business Applications › Forums › SQL › Spotting null values using CASE clause

Tagged: CASE clause in SQL

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • April 23, 2022 at 12:46 pm #144
    Admin
    Keymaster

      Here is the problem:

      All of the questions in this quiz refer to the open source Chinook Database. Please familiarize yourself with the ER diagram in order to familiarize yourself with the table and column names in order to write accurate queries and get the appropriate answers.

      Profiling the Customers table, answer the following question.

      Are there any columns with null values? Indicate any below. Select all that apply.

      Company

      Postal Code

      Fax

      Address

      Phone

      FirstName

      Here is my tentative solution:

      SELECT *
      FROM customers
      WHERE Company IS NULL

      Source: https://www.coursera.org/learn/sql-for-data-science

      With that query, it is possible to get null values for Company. But not able to figure out how to include other fields (postal code, fax…) with it.


      Reply


      For starters, you’re returning rows, when the question asked about columns

      see the difference?

      and supposing you were to do something like this —

      SELECT *
        FROM customers
       WHERE Company IS NULL
          OR PostalCode IS NULL
          OR Fax IS NULL
      etc.

      Still, you will be returning null values.

      Doesn’t address the question asked — Are there any columns with null values?

      the answer to this question should be a flat YES or NO.

      but more instructive would be to identify the columns.

      SELECT CASE WHEN COUNT(*) > COUNT(Company)
                  THEN 'Company has NULLs'
                  ELSE NULL END
           , CASE WHEN COUNT(*) > COUNT(PostalCode)
                  THEN 'PostalCode has NULLs'
                  ELSE NULL END
         etc.
        FROM Customers
    • Author
      Posts
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Primary Sidebar

    profile for Techcosec Limited on Stack Exchange, a network of free, community-driven Q&A sites

    RSS CS50’s Introduction to Computer Science by Harvard University on Edx

    • How to print winner January 21, 2023
    • find_min function and infinite loop when a candidate not winner in first instance January 17, 2023
    • Bool variable won and print_winner function January 12, 2023
    • True condition with while loop January 6, 2023
    • How to finally display result in tabular form of choices entered by voters December 12, 2022

    Subscribe via Email

    Enter your email address to subscribe and receive notifications of new posts by email.

    This website hosted on WP Engine

    Initiative by Digital Splendid OPC Pvt. Ltd. & Techcosec Limited