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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:26:46+00:00 2026-06-02T03:26:46+00:00

I am having problems with querying and grouping. I am needing the following output:

  • 0

I am having problems with querying and grouping.

I am needing the following output:

officr, cbal, sname  
ABC, 500.00, TOM JONES  
ABC, 200.00, SUE JONES  
ABC TOTAL 700.00  

RAR, 100.10, JOE SMITH  
RAR, 200.05,  MILES SMITH  
RAR TOTAL 300.15  

SQL below produces the error:

[DB2 for i5/OS]SQL0122 – Column SNAME or expression in SELECT list not valid.

SELECT
    lnmast.officr,  SUM(LNMAST.CBAL), lnmast.sname
FROM
    LNMAST
WHERE LNMAST.RATCOD IN (6,7,8) AND STATUS NOT IN ('2','8')
group by lnmast.officr
  • 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-02T03:26:47+00:00Added an answer on June 2, 2026 at 3:26 am

    GROUP BY GROUPING SETS is a POWERFUL tool for grouping/cubing data. It lets you combine non-aggregated data with aggregated data in one query result.

    SELECT lnmast.officr,  SUM(LNMAST.CBAL), lnmast.sname
    FROM LNMAST
    WHERE LNMAST.RATCOD IN (6,7,8) 
      AND STATUS NOT IN ('2','8')
    GROUP BY GROUPING SETS ((lnmast.officr, lnmast.sname),(lnmast.officr))
    

    An example from IBM DOCS: http://www.ibm.com/support/knowledgecenter/en/... :

      SELECT WEEK(SALES_DATE) AS WEEK,
             DAYOFWEEK(SALES_DATE) AS DAY_WEEK,
             SALES_PERSON, SUM(SALES) AS UNITS_SOLD       
      FROM SALES 
      WHERE WEEK(SALES_DATE) = 13
      GROUP BY GROUPING SETS ( (WEEK(SALES_DATE), SALES_PERSON),
                               (DAYOFWEEK(SALES_DATE), SALES_PERSON))
      ORDER BY WEEK, DAY_WEEK, SALES_PERSON
    

    This results in:

      WEEK        DAY_WEEK    SALES_PERSON    UNITS_SOLD 
      ----------- ----------- --------------- -----------
               13           - GOUNOT                   32
               13           - LEE                      33
               13           - LUCCHESSI                 8
                -           6 GOUNOT                   11
                -           6 LEE                      12
                -           6 LUCCHESSI                 4
                -           7 GOUNOT                   21
                -           7 LEE                      21
                -           7 LUCCHESSI                 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems compiling the following program. I'm using gcc -framework Foundation inherit8.1m and
I'm having problems querying the entity model to get additional information. My db has
I am having some problems with regexp_extract: I am querying on a tab-delimited file,
Having problems with the output of this formula: typedef struct { float t, Vx,
Having problems with a small awk script, Im trying to choose the newest of
Having problems iterating. Problem has to do with const correctness, I think. I assume
Having problems with the combining of two statements in a controller. Both statements work
Im having problems with classpaths. I have used them before with import but I'm
im having problems starting a codeigniter project, the problem is that when i do
im having problems on how to save the content of an array in an

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.