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 6983069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:22:15+00:00 2026-05-27T18:22:15+00:00

I have a long sql query that calculates a few things about payments and

  • 0

I have a long sql query that calculates a few things about payments and shipments. In some cases the value is null. I think that’s because there’s being divided by 0.

Here’s a small part of my query:

     ROUND(sum(case when shipping_method = 'c' AND (paid_amount - shipping_costs) < 70 then 1 end) * 100 / sum(case when shipping_method = 'c' then 1 end),2) as co_less_70,

I think that when this part is 0: sum(case when shipping_method = 'colissimo' then 1 end),2) my query shows null. Is there any way to assign a default value for this co_less_70 column?

  • 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-05-27T18:22:15+00:00Added an answer on May 27, 2026 at 6:22 pm

    Yes. You can use the COALESCE() function:

    http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_coalesce
    Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.

    In your code:

    COALESCE(
        ROUND(sum(case when shipping_method = 'c' AND (paid_amount - shipping_costs) < 70 then 1 end) * 100 / sum(case when shipping_method = 'c' then 1 end),2),
        0
    ) AS co_less_70
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this quite long query that should give me some information about shipments,
I have a SQL query that takes a very long time to run on
I have a reasonably long SQL query that I need to run in a
I have a long-running SQL Server 2005 query that I have been hoping to
I have two long type columns that I want to concat during sql query.
after a very long sql query a have a result that is in this
I have a pretty long SQL query that I use to, for all of
I have a long running SQL query inside a page that I've sped up
I have created a SQL query that runs on SQL Server 2008. For some
I have a long running SQL statement that I want to run, and no

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.