473,624 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_MO NTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MO NTHS(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 15466
ge***********@e u.watsonwyatt.c om (George) wrote in message news:<d4******* *************** ****@posting.go ogle.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_MO NTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MO NTHS(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.o racle 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_MO NTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MO NTHS(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_MO NTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MO NTHS(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_MO NTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MO NTHS(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_MO NTHS(SYSDATE, -2))+1
and LAST_DAY(ADD_MO NTHS(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
6447
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
1
4167
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 couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
1
22508
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 from my query, e.g. "select name, hours, overtime, hours+overtime as total" Name Hours Overtime Total -------------------------------------- Bloggs 8 2 10
2
9761
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) problem can avoid these technicalities: the original table has columns A1, A2, B1, B2, C1, C2.
1
2758
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 have a table containing records for each job done, the records contain date, employee name, job done (a code representing the type of job), cost code (another code), regular hours, and overtime hours. The tricky part is that more than one job can...
30
3365
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 the program and have been self taught, so here goes. As you can see by the image link i am creating an appointment diary for a garage,its going ok untill i created the "Hours remaing" text box The main subform adds up the hours booked in and...
1
3456
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 wednesday. I created a table begin_time and a table end_time and day. Then i wanted to compare the times with the local time like$time = date("H"); $day = date("l");. I thought something like this query: $query = "SELECT * FROM dj WHERE...
7
4045
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 it 7 rows more respect tbl_registry can you tell my why I have this situation:
3
742
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 WW_REC_1 where trans_date between last_DAY(ADD_MONTHS(SYSDATE, -2))+1 and LAST_DAY(ADD_MONTHS(SYSDATE,-1))
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.