Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I know - not specifically .net; but I thought maybe one of the db gurus might get this. Basically what I have is this. I want to get a total elaptime for each numericid, cdclass and cdsubclass

 

I have two tables as follows

 

table 1:

numericid

cdclass

cdsubclass

 

table 2:

numericid

elaptime

 

table1 and table2 are related by numericid

 

I hope this explains what it is I am after - been at this for hours:(

If I need to clarify I will try

Posted

If i could guess, You are trying to take Sum of Fields

Please try some thing like this

 

Select sum(numericID), Sum(CdClass) , Sum(cdSubClass) from Table1;

 

it will return you only one row. containing Total of each row.

 

Tell me one thing, how rows are managed in tables.

Each NUMERIC ID have more then one class and subclasses

 

then it should be some thing like this

 

Select Sum(cdclass) , Sum(cdsubclass) from Tables1 Where numericid = x;

 

x = some digit or id you have specifiied.

 

If you need more please contact me on my email address coz this forum is only for .NET related questions.

The one and only

Dr. Madz

eee-m@il

  • *Experts*
Posted

Actually, if you want a SUM per Class and Subclass, use this:

SELECT t1.CDClass, t1.CDSubclass, SUM(t2.ElapTime)
FROM Table1 AS t1
INNER JOIN Table2 AS t2 ON t1.NumericID = t2.NumericID
GROUP BY t1.CDClass, t1.CDSubclass

 

The Group By is the key - it defines a grouping so that you can run aggregate queries on columns, such as the SUM() above PER a column (or multiple columns, as shown).

 

You'll have to use the table.column name syntax in the select since some of the columns repeat between tables (it's genereally a good idea to use table.column names in a SELECT instead of just column name).

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...