Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8214401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:27:01+00:00 2026-06-07T11:27:01+00:00

Is there a way to modify this query to return ‘0’ in the Grade

  • 0

Is there a way to modify this query to return ‘0’ in the Grade column if no records are found? Right now when nothing is found I get a blank row.

SELECT  COALESCE(Score, 0) AS Score, COALESCE(Grade,0) AS Grade, LAST_UPDATE, '' as  dummy
FROM (
SELECT (CASE ScanName WHEN '%=APP%' THEN '= Network System' END) AS   System, 
(sum(CASE severity WHEN 1 THEN 10 WHEN 2 THEN 9 WHEN 3 THEN 6 WHEN 4 THEN 3    
END)/COUNT(severity )) AS Score,
(sum(CASE severity WHEN 1 THEN 10 WHEN 2 THEN 9 WHEN 3 THEN 6 WHEN 4 THEN 3   
END)/COUNT(severity )) AS Grade, LAST_UPDATE 

FROM missing_internal

WHERE ScanName like '%APP%'

and LAST_UPDATE >= SUBDATE((SELECT MAX(LAST_UPDATE) from missing_internal), INTERVAL 1 day) 
HAVING System IS NOT NULL  
LIMIT 1

UNION ALL 

SELECT NULL AS Score, NULL AS Grade, 0 AS LAST_UPDATE, '' as dummy

ORDER BY LAST_UPDATE DESC

)  as T2
LIMIT 1;

Score and Grade are the same on purpose as I am using a separate script to apply a letter grade to the score.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:27:04+00:00Added an answer on June 7, 2026 at 11:27 am

    Take a look at the COALESCE function …

    If i well understood your question the below query should do exactly what you want(getting zeros when now rows are returned) :

    SELECT COALESCE(Score, 0) AS Score, COALESCE(Grade,0) AS Grade, LAST_UPDATE 
    FROM (
    SELECT (CASE ScanName WHEN 'APP' THEN 'Network System' END) AS System, 
    (sum(CASE severity WHEN 1 THEN 10 WHEN 2 THEN 9 WHEN 3 THEN 6 WHEN 4 THEN 3    
    END)/COUNT(severity )) AS Score,
    (sum(CASE severity WHEN 1 THEN 10 WHEN 2 THEN 9 WHEN 3 THEN 6 WHEN 4 THEN 3   
    END)/COUNT(severity )) AS Grade, LAST_UPDATE
    
    FROM missing_internal
    
    WHERE ScanName like '%APP%'
    
    and LAST_UPDATE >= SUBDATE((SELECT MAX(LAST_UPDATE) from missing_internal), INTERVAL 1 day)
    HAVING System IS NOT NULL  
    LIMIT 1
    
    UNION ALL 
    
    SELECT NULL AS Score, NULL AS Grade, 0 AS LAST_UPDATE 
    
    ORDER BY LAST_UPDATE DESC
    ) AS T2
    LIMIT 1;
    

    I have not tested the query, so you could need to arrange it … However take the idea …

    If you want to get zero only when a column return null result, you can use COALESCE in the same way as above example :

    COALESCE(sum(CASE severity WHEN 1 THEN 10 WHEN 2 THEN 9 WHEN 3 THEN 6 WHEN 4 THEN 3   
    END)/COUNT(severity ), 0) AS Grade
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to modify the printf in order to output string on
Is there any way to modify the CSS properties of one table's cells based
is there a simple way to modify the InnerXml of a XElement? supose we
In git, is there any (simple) way to modify the index so that only
Is there a way to allow admins to modify the content of simple static
Is there an easy-ish way to modify the webform-form-tpl.php template to show disclaimer text
I have the following query. Is there an easy way that I could sort
Is there a way to modify the link to a tab in jquery ui
Is there any way to modify the mongo values in a where-clause in a
Is there way to get file from windows xp command prompt? I tried to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.