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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:10:37+00:00 2026-06-11T20:10:37+00:00

I have a Leave table as per below: MONTH | NAME | DAY1 |

  • 0

I have a Leave table as per below:

MONTH | NAME | DAY1 | DAY2 | DAY3 | ... | DAY31
------------------------------------------------      
      |      |      |      |      | ... |     

Columns DAY1 to DAY31 keep the number of hours the named person has not been in the office.

I need a query to generate this output:

MONTH | NAME | TOTAL_MONTH_HOURS
---------------------------------      
      |      |        

where TOTAL_MONTH_HOURS is sum of all hours in the month; i.e. DAY1 + DAY2 + ... + DAY30+DAY31

How should I write this query? Is there any way to escape having to sum all the columns as I did above? I encounter similar problems from time to time where tables get even bigger!

Note: some columns may be NULL due to variant month lengths.

  • 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-11T20:10:38+00:00Added an answer on June 11, 2026 at 8:10 pm

    The simplest, given the current table structure, is simply to do exactly that –

    Select Month, Name, Day1+Day2+Day3....+Day31 Total_Month_Hours
      From Tbl
    

    Now, if it is possible to have NULLs and that being the reason for the question, wrap them with COALESCE. COALESCE is part of the ANSI SQL99 standard and has support on all major RDBMS (MySQL Oracle SQLite PostgreSQL SQL Server).

    Select Month,
           Name,
           COALESCE(Day1,0)+COALESCE(Day2,0)+...+COALESCE(Day31,0) Total_Month_Hours
      From Tbl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please suppose that I have a table with a certain, unspecified number of columns.
I have these two tables. Leave Table from_date to_date user_id 2011-12-01 2011-12-01 1 2011-12-01
I have 2 tables with structure as Emp Table id name 001 Smith 002
I have a table like this: |sub_account|name|email| |-----------|----|-----| // same account and same name:
Assuming that we have the following table: Person: PersonID, Name, Age, Gender And we
I have a table with some fixed columns id,title,created.., but there I need put
Here I have a Leave table with column of AttendanceId(PK, incremental), EmpId, Check_In_Time, Check_Out_Time,
I have 4 tables like shown below Table: leave_request +------------+----------+--------------+------------+----------------------+ | request_id | staff_id
I have a table called create with only one column called name of type
I have a table only consisting of two columns: ObjectID||PropertyID The task: get the

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.