If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL Sub Query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-04, 11:32
HomersDonut HomersDonut is offline
Registered User
 
Join Date: Nov 2002
Posts: 37
SQL Sub Query help

I have four queries that I am using: 4 calls 3, 3 calls 2 and 1.
This was the only way to get the results I wanted, with my knowledge level.

The table it is coming from appears to have 3 keys, I am guessing that they are concatinated, Year,Incident No, and Sequence.

I was wondering if I can make a sub query to include them all, so i dont have 4 queries doing what one can.

Thanks in advance to the smart people out there.

1)
SELECT [Operation Entry].[Year Assoc], [Operation Entry].[Incident No], [Operation Entry].[Sequence No], [Operation Entry].[Outage Minutes], [Operation Entry].[KVA-Minutes], [Operation Entry].[Class ID No], [Operation Entry].RecDate
FROM [Operation Entry]
WHERE ((([Operation Entry].[Outage Minutes])>5) AND (([Operation Entry].[Class ID No])="4"));

2)
SELECT [Operation Entry].[Incident No], Max([Operation Entry]![KVA Out]) AS MaxKVAOut, [Operation Entry].[Year Assoc]
FROM [Operation Entry]
WHERE ((([Operation Entry].[Class ID No])="4"))
GROUP BY [Operation Entry].[Incident No], [Operation Entry].[Year Assoc], [Operation Entry].[Year Assoc];

3)
SELECT [1JohnTest].[Incident No], [2JohnTestMaxKva].MaxKVAOut, Sum([1JohnTest].[KVA-Minutes]) AS [SumOfKVA-Minutes]
FROM 2JohnTestMaxKva INNER JOIN 1JohnTest ON ([2JohnTestMaxKva].[Year Assoc] = [1JohnTest].[Year Assoc]) AND ([2JohnTestMaxKva].[Incident No] = [1JohnTest].[Incident No])
WHERE ((([1JohnTest].RecDate) Between [Type the beginning date:] And [Type the ending date:]))
GROUP BY [1JohnTest].[Incident No], [2JohnTestMaxKva].MaxKVAOut;

4)
SELECT Count([3JohnTestTotals].[Incident No]) AS [# Incidents], Sum([3JohnTestTotals].MaxKVAOut) AS [SAIFI KVA], Sum([3JohnTestTotals].[SumOfKVA-Minutes]) AS [KVA-Min]
FROM 3JohnTestTotals;

Last edited by HomersDonut; 04-08-04 at 09:41.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On