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

  • Home
  • SEARCH
  • 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 827315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:33:21+00:00 2026-05-15T03:33:21+00:00

Based on the following table Area S1 S2 S3 S4 ——————– A1 5 10

  • 0

Based on the following table

Area  S1 S2 S3 S4 
--------------------
A1    5  10 20 0
A2    11 19 15 20
A3    0  0  0  20

I want to generate an output that will give the number of columns not having “0”.

So the output would be

Area  S1 S2 S3 S4   Count 
-------------------------
A1    5  10 20 0    3
A2    11 19 15 20   4
A3    0  0  0  20   1
  • 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-15T03:33:22+00:00Added an answer on May 15, 2026 at 3:33 am

    One way would be to add the result of case statements together:

    select area, s1, s2, s3, s4,
        case when S1 <> 0 then 1 else 0 end +
        case when S2 <> 0 then 1 else 0 end +
        case when S3 <> 0 then 1 else 0 end +
        case when S4 <> 0 then 1 else 0 end as Count
    from YourTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on following AreaState table Area State ------------------- A1 Active A1 Active A1 Active
Based on the following table ID Effort Name ------------------------- 1 1 A 2 1
based on the following table Name --------- A A A B B C C
Found the following in an Oracle-based application that we're migrating (generalized) : SELECT Table1.Category1,
I have the following requirement: Based on some user input, I need to generate
I have the following table schema: CREATE TABLE [Foo]( [id] [int] NOT NULL, [name]
A PHP script is generating the following table panel based on the data from
I have the following Table example here: http://jsfiddle.net/Lu9y3/ Which is based on the Telerik
I have the following table in a database. I want to be able to
Based on the following table Table_A ID Rev Description ----------------------------------- 1 1 Some text.

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.