473,386 Members | 1,830 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,386 software developers and data experts.

Totaling Group bys?

Table1:
SessionID int
Hours int
....
SessionID Hours
111 3
222 2
333 3
444 2

Table2:
SessionID int
RegistrationID int
....
RegistrationID SessionID
888 111
888 444
777 111
666 222
666 333

I want to sum the hours for each person spent in sessions.

Results I'd like to see:
RegistrationID hours
888 5
777 3
666 4

What is not working:
Select hours, registrationID
from
table1, table2
where
table1.SessionID = table2.sessionID
Group by registrationID, hours

This adds up ALL the hours and then groups them by person.

Any help?

John Mosey "Humping your theoretical mom since 1993"
Complaints can be sent to ab***@mosey.com
The sun rises in the east, dumbass

Jul 20 '05 #1
2 2788
Hi

There are plenty of examples in books online for how to do select
statements.

Check out the information regarding joining tables and the select statement
at
http://msdn.microsoft.com/library/de...qd_09_610z.asp

http://msdn.microsoft.com/library/de...asp?frame=true

The following should give you the result required:
Select SUM(t.hours) as Hours, s.registrationID
from table1 t JOIN table2 s ON t.SessionID = s.sessionID
Group by s.registrationID

John

"The Only Mosey" <jo**@mosey.commuicate> wrote in message
news:bm*********@drn.newsguy.com...
Table1:
SessionID int
Hours int
...
SessionID Hours
111 3
222 2
333 3
444 2

Table2:
SessionID int
RegistrationID int
...
RegistrationID SessionID
888 111
888 444
777 111
666 222
666 333

I want to sum the hours for each person spent in sessions.

Results I'd like to see:
RegistrationID hours
888 5
777 3
666 4

What is not working:
Select hours, registrationID
from
table1, table2
where
table1.SessionID = table2.sessionID
Group by registrationID, hours

This adds up ALL the hours and then groups them by person.

Any help?

John Mosey "Humping your theoretical mom since 1993"
Complaints can be sent to ab***@mosey.com
The sun rises in the east, dumbass

Jul 20 '05 #2
The Only Mosey <jo**@mosey.commuicate> wrote in message news:<bm*********@drn.newsguy.com>...
Table1:
SessionID int
Hours int
...
SessionID Hours
111 3
222 2
333 3
444 2

Table2:
SessionID int
RegistrationID int
...
RegistrationID SessionID
888 111
888 444
777 111
666 222
666 333

I want to sum the hours for each person spent in sessions.

Results I'd like to see:
RegistrationID hours
888 5
777 3
666 4

What is not working:
Select hours, registrationID
from
table1, table2
where
table1.SessionID = table2.sessionID
Group by registrationID, hours

This adds up ALL the hours and then groups them by person.

Any help?

John Mosey "Humping your theoretical mom since 1993"
Complaints can be sent to ab***@mosey.com
The sun rises in the east, dumbass


create table table1 (sessionid int, hours int)
insert into table1 select 111, 3
insert into table1 select 222, 2
insert into table1 select 333, 3
insert into table1 select 444, 2

create table table2 (registrationid int, sessionid int)
insert into table2 select 888, 111
insert into table2 select 888, 444
insert into table2 select 777, 111
insert into table2 select 666, 222
insert into table2 select 666, 333

select t2.registrationid, sum(t1.hours)
from table2 t2 join table1 t1
on t2.sessionid = t1.sessionid
group by t2.registrationid

-- drop table table1
-- drop table table2

Simon
Jul 20 '05 #3

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

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
2
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
0
by: Sal | last post by:
Hi, I have a table in which I performed all of my complex calc's so I can have a simple report to sub total and group. My report works fine except for the footers. I have groupings by city and...
3
by: Sebastian | last post by:
Hello all I have a report where I have two nested groups. I know there are only three standard options for running sum: None, Over Group and Over All. I have a MyTextBox in detail section where...
2
by: Ryker | last post by:
In table A I have a field called Color. I have a color report that groups the colors and prints the total. One section will list and total all the records that have red in the color field, one...
4
by: NormAmst | last post by:
I have a list of CPU processing times and job durations for an entire department at work. There are 3 classifications I am maintaining. CPU time during peak hours , CPU time during non peak hours...
2
by: sukitmw | last post by:
Hi, I'm trying to sum each column and each row of a datagrid and put the totals of columns at the bottom of each column and totals of row at the last empty column. How do I do this? I found...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
0
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...
0
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,...
0
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...

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.