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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:25:07+00:00 2026-05-28T04:25:07+00:00

I am working with a SQL Library (Programming library, ANSI SQL Compliant, called ABS

  • 0

I am working with a SQL Library (Programming library, ANSI SQL Compliant, called ABS Database,(http://www.componentace.com/help/absdb_manual/absdbmanual_content.htm). It supports the various joins, CASE, etc…

I have a single table (appt), which is a table of appointments.

ApptKey - Integer - Primary Key
SA_ID -  Integer  (a person’s ID, think employee number),
Layer - Integer – only 4 different values, 1, 2, 3 or 4 (think Appt Category)
Number_Of_Minutes  - Integer – the length of the appointment

Note that some SA_ID/Layer combinations may be empty (i.e. no rows for that combination). Other SA_ID/Layer combinations may have multiple rows (I am not showing other columns as they are not relevant here). I need a report to show the sum of minutes, for each person (SA_ID), for each layer, in one row… i.e. each SA_ID has their own row, showing the sum for Layer =1, the sum for layer =2 , the sum for Layer =3, and the sum for layer = 4.

Example data…

SA_ID         LAYER        Number_of_Minutes
1             1            10
1             1            30
2             1            10
3             2            10
1             4            10

I need a query that gives this result.

SA_ID      LAYER_1     LAYER_2    LAYER_3     LAYER_4
1          40          0          0           10
2          10          0          0           0
3          0           10         0           0

I need this type of format, because this query feeds a Chart/graph component…

I think I need to use a right join a multiple correlated subqueries, but I just can’t get it to work. Is this the right approach. What I have below runs, but as a straight join. Can I (or how do I) rewrite this to use a right outer join? Is a right outer join the best approach?

select g.sa_id,  l1.totalsum, l2.totalsum, l3.totalsum, l4.totalsum
from  (select sa_id, layer, sum(number_of_minutes) totalsum from appt where layer = 1 group by sa_id, layer) l1,
           (select sa_id, layer, sum(number_of_minutes) totalsum from appt where layer = 2 group by sa_id, layer) l2,
           (select sa_id, layer, sum(number_of_minutes) totalsum from appt where layer = 3 group by sa_id, layer) l3,
          (select sa_id, layer, sum(number_of_minutes) totalsum from appt where layer = 4 group by sa_id, layer) l4,
          (select distinct sa_id "sa_id" from appt) g
where
      (l1.sa_id = g.sa_id)
and   (l2.sa_id = g.sa_id)
and   (l3.sa_id = g.sa_id)
and   (l4.sa_id = g.sa_id)
  • 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-28T04:25:08+00:00Added an answer on May 28, 2026 at 4:25 am
    SELECT SA_ID,
    SUM(CASE WHEN LAYER = 1 THEN Number_of_Minutes ELSE 0 END) AS LAYER_1, 
    SUM(CASE WHEN LAYER = 2 THEN Number_of_Minutes ELSE 0 END) AS LAYER_2,
    SUM(CASE WHEN LAYER = 3 THEN Number_of_Minutes ELSE 0 END) AS LAYER_3,
    SUM(CASE WHEN LAYER = 4 THEN Number_of_Minutes ELSE 0 END) AS LAYER_4
    FROM Appt
    GROUP BY SA_ID
    

    EDIT: Because it supports CASE expressions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running through the sql access example on the MSDN website (http://msdn.microsoft.com/en-us/library/hh202876(v=VS.92).aspx) and i
I am working with SQL Server and I want to set the Database password
I am working on saving twitter search results into a database (SQL Server) and
I'm looking for a library that will simplify working with SQL in C++. I'm
I am stuck figuring out a working SQL Query for the fallowing: I need
Added: Working with SQL Server 2000 and 2005, so has to work on both.
I'm working with SQL Server 2005 and Windows Server 2000 and wonder if there
I am working on sql server where i want to save html code into
I am working with SQL Server 2000, and trying to change the data type
I'm working on SQL server 2005 and I have a very simple stored procedure:

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.