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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:17:25+00:00 2026-06-01T00:17:25+00:00

I have some records after SQL generating: YEARS MONTHS SUMMONTH SUMQUARTER QTR —– ——

  • 0

I have some records after SQL generating:

YEARS MONTHS SUMMONTH SUMQUARTER QTR
----- ------ -------- ---------- ---
 2009 Jan      363639     855922 1   
 2009 Feb      128305     855922 1   
 2009 Mar      363978     855922 1   
 2009 Apr      376633    1058871 2   
 2009 May      299140    1058871 2   
 2009 Jun      383098    1058871 2   
 2009 Jul      435000    1063577 3   
 2009 Aug      266227    1063577 3   
 2009 Sep      362350    1063577 3   
 2009 Oct      449366    1017906 4   
 2009 Nov      280943    1017906 4   
 2009 Dec      287597    1017906 4   
 2010 Jan      418277     661083 1   
 2010 Feb      129895     661083 1   
 2010 Mar      112911     661083 1   
 2010 Apr      163593     685625 2   
 2010 May      228505     685625 2   
 2010 Jun      293527     685625 2   
 2010 Jul      451608    1044364 3   
 2010 Aug      356683    1044364 3   
 2010 Sep      236073    1044364 3   
 2010 Oct      247365     798925 4   
 2010 Nov      414100     798925 4   
 2010 Dec      137460     798925 4   

 24 rows selected 

The SUMQUARTER column sum up each quarter of a year…
The qtr specify it belongs to which quarter.

The problem is how to have a subtraction of sumquarter between 2 different years to get the specific query result?

The difference is not the: max value-min value.
It is the user-defined value that he want to input…

Let say…
For example, the user want to see the substraction(sumquarter) between 2009 qtr=2 and 2010 qtr=2,
user may change the parameter(years,qtr) of sql to view the record.

This mean the result should be: (1058871 – 685625)

Here is the SQL that I am currently using:

select years,months,summonth,sumquarter,qtr

from(
        select years,months,summonth,sumhour,hours,to_char(ym, 'Q') qtr,
                sum(sumhour) over(partition by years || to_char(ym, 'Q') order by years || to_char(ym, 'Q')) sumquarter,ym,
                count(days) over(partition by years,months,hours) days_month

        from(
                select   years, months, days, hours, mins, sumHour,
                         SUM (sumHour) OVER (PARTITION BY years,months,days) sumDay,
                         SUM (sumHour) OVER (PARTITION BY years,months) sumMonth,
                         SUM (sumHour) OVER (PARTITION BY years) sumyear,
                         to_date(years || months, 'YYYYMon', 'NLS_DATE_LANGUAGE=American') ym
                from  (

                        SELECT x.years, x.months, x.days, x.hours, x.mins, sum(x.value) as sumHour
                        FROM xmltest,
                             XMLTABLE ('$d/cdata/name' passing doc as "d"
                                        COLUMNS
                                          years integer path 'year',
                                          months varchar(3) path 'month',
                                          days varchar(2) path 'day',
                                          hours varchar(2) path 'hour',
                                          mins varchar(2) path 'minute',
                                          value float path 'value'
                                       ) as X
                        group by x.years, x.months, x.days, x.hours, x.mins
                        order by x.years, x.months, x.days
                      )
             )
    )

  group by years,months,summonth,sumquarter,qtr,ym
  order by ym

The sql pattern maybe something like this:…??

select ((select sumquarter from table where years=2009 and qtr=2) - (select sumquarter from table where years=2010 and qtr=2)) from table

Actually, it doesn’t work…

The result maybe look in this view:

SUBTRACT 
---------- 
373246

Thanks everyone helps!!:)

  • 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-01T00:17:27+00:00Added an answer on June 1, 2026 at 12:17 am

    I’d use the following:

    select 
    ((select sumquarter from table where years=2009 and qtr=2 and rownum=1) - 
     (select sumquarter from table where years=2010 and qtr=2 and rownum=1)) as substract
    from dual
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some records like this: ID Personel_Code Time --- ------------- ------ 1 0011
I have some XML which contains records and sub records, like this: <data> <record
I have some dirty resource usage records in t_resourcetable which looks like this resNo
i have SOQL query which queries for some records based on a where condition.
I have created a View which prompts the user to input some records with
Hi experts: I have a table Called tblAlarm and it has some records like
I have a table within my database that has many records, some records share
I have a dataset with some 30 records in it. I want to update
I have to show records in such a way that some selected records should
I have an Action that requires authentication. The action method creates some records with

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.