473,377 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

Select query for sum of hours

Hi,

The sql query below returns data in the 'note' field from a table
called ww_rec_1 from the previous month and displays the sum of hours
for each category.

SELECT note,SUM(hours)FROM WW_REC_1
where trans_date between
last_DAY(ADD_MONTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MONTHS(SYSDATE,-1))
GROUP BY NOTE

This is the returned data:

"NOTE", "SUM(HOURS)"

"ACT", -330864.75
"CHG", -165.25
"EXT", 331108.5
"INT", 45

I need to add together the sum of hours for specified data in the note
field. So in this case I want to add together the sum of hours for
'ACT' and 'CHG'. I also need to add together the sum of hours for
'EXT' and 'INT'.

Can anyone help me out with this?

Thanks in advance

George
Jul 19 '05 #1
3 15441
ge***********@eu.watsonwyatt.com (George) wrote in message news:<d4**************************@posting.google. com>...
Hi,

The sql query below returns data in the 'note' field from a table
called ww_rec_1 from the previous month and displays the sum of hours
for each category.

SELECT note,SUM(hours)FROM WW_REC_1
where trans_date between
last_DAY(ADD_MONTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MONTHS(SYSDATE,-1))
GROUP BY NOTE

This is the returned data:

"NOTE", "SUM(HOURS)"

"ACT", -330864.75
"CHG", -165.25
"EXT", 331108.5
"INT", 45

I need to add together the sum of hours for specified data in the note
field. So in this case I want to add together the sum of hours for
'ACT' and 'CHG'. I also need to add together the sum of hours for
'EXT' and 'INT'.

Can anyone help me out with this?

Thanks in advance

George


First, this probably should have been posted to
comp.databases.oracle.misc rather than the obsolete
comp.database.oracle group. When a newsgroup has subgroups you should
generally post to the subgroups and not the group.

There are several ways to solve you query. One method would be to
change the from clase to be a FROM (Select .... where in the new
select you use a case statement to return ACT for CHG and EXT for INT
so that to the outer query the NOTE values are the same group value.

HTH -- Mark D Powell --
Jul 19 '05 #2
> SELECT note,SUM(hours)FROM WW_REC_1
where trans_date between
last_DAY(ADD_MONTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MONTHS(SYSDATE,-1))
GROUP BY NOTE

This is the returned data:

"NOTE", "SUM(HOURS)"

"ACT", -330864.75
"CHG", -165.25
"EXT", 331108.5
"INT", 45

I need to add together the sum of hours for specified data in the note
field. So in this case I want to add together the sum of hours for
'ACT' and 'CHG'. I also need to add together the sum of hours for
'EXT' and 'INT'.


1. add together ...
SELECT SUM(hours) FROM WW_REC_1
where trans_date between
last_DAY(ADD_MONTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MONTHS(SYSDATE,-1))
where note='ACT' OR note='CHG'

2. also add together ...
SELECT SUM(hours) FROM WW_REC_1
where trans_date between
last_DAY(ADD_MONTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MONTHS(SYSDATE,-1))
where note='EXT' OR note='INT'
Jul 19 '05 #3
select sum ( sum_hours ),
note_group
from (
select decode
(
note,
'ACT', 'ACT-CHG',
'CHG', 'ACT-CHG',
null
) note_group,
decode
(
note,
'EXT', 'EXT-INT',
'INT', 'EXT-INT',
null
) note_group,
sum_hours
from (
SELECT note,SUM(hours) sum_hours FROM WW_REC_1
where trans_date between
last_DAY(ADD_MONTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MONTHS(SYSDATE,-1))
GROUP BY NOTE
)
)
group by
note_group;
Pratap
Cognizant Technology Solutions, India
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
1
by: davidboyd24 | last post by:
Im currently having difficulty trying to write an SQL query in Access which will add two columns together to calculate a totals column. For example... I was hoping to get the below resultset...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
1
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I...
30
by: Noob | last post by:
ftp://ukcassassin:winston@www.ukcassassin.pwp.blueyonder.co.uk/htdocs/Diary%20Form.bmp Hi all I will appologise in advance for my lack of knowledge of access and its working as i am quite new to...
1
by: djpaul | last post by:
Hello guys, I'm busy writing a website for dj's. But i wanted to show the picture and more stuff of the dj who's playing music between a few hours. Let's say he works between 18:00 and 21:00 on...
7
by: Mike1961 | last post by:
Hi there. Well the situation is this, I have two tables: 1) tbl_registry where rows with code = 123 are 35 ; 1) tbl_Registered where rows with code = 123 are 43 In tbl_Registered I have...
3
by: George | last post by:
Hi, The sql query below returns data in the 'note' field from a table called ww_rec_1 from the previous month and displays the sum of hours for each category. SELECT note,SUM(hours)FROM...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.