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 Plz He[p!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-27-03, 11:44
arin_am arin_am is offline
Registered User
 
Join Date: Jun 2003
Posts: 34
Sql Plz He[p!!

We have a table which looks like the following...

Rep_det
=========

Job_num Rep_num Dim1 Dim2 Dim3 Met1 Met2 Met3
------- -------- ---- ---- ---- ---- ---- ----
100 1 AK 200 300
100 1 CA 500 200
100 1 NY 1000 350
100 1 MA 750 250
200 1 CA 250 350
200 1 NY 1000 700
200 1 MA 500 100
200 1 NJ 750 1100

WE WANT A REPORT AS SHOWN BELOW...

STATE CID SID PRIOR_CID PRIOR_SID
----- --- --- --------- ---------
AK 200 300
cA 250 350 500 200
NY 1000 700 1000 350
MA 500 100 750 250
NJ 750 1000

If you would notice that AK is not present in current "Job" so current "CID" / "SID" is NULL but it was present in the previous "Job" so there are entries in PRIOR_CID / PRIOR_SID.

Its opposite for NJ.

Could anyone help me out with a query for the same. Would really appreciate a help. I have attched the above so that you have a look.

Thanks.
Attached Files
File Type: txt query.txt (619 Bytes, 33 views)
Reply With Quote
  #2 (permalink)  
Old 08-27-03, 12:47
dmmac dmmac is offline
Registered User
 
Join Date: Aug 2003
Location: Massachusetts, USA
Posts: 106
Re: Sql Plz He[p!!

The output in your post was hard to understand so I'm a little unsure the below suggestion is what you're looking for:

SELECT dim1 STATE, MAX(dim2) CID, MAX(dim3) SID,
MAX(met1) PRIOR_CID, MAX(met2) PRIOR_SID
FROM table
GROUP BY dim1

The above assumes using MA as an example that the data in the table is this:

Job_num Rep_num Dim1 Dim2 Dim3 Met1 Met2
100 1 MA 750 250
200 1 MA 500 100

The purpose of the MAX in the SELECT is to collapse null/value.

If this is not the route you meant, my I suggest using a spreadsheet to accurately show the data to columns in the table rather than a notepad document.

Quote:
Originally posted by arin_am
We have a table which looks like the following...

Rep_det
=========

Job_num Rep_num Dim1 Dim2 Dim3 Met1 Met2 Met3
------- -------- ---- ---- ---- ---- ---- ----
100 1 AK 200 300
100 1 CA 500 200
100 1 NY 1000 350
100 1 MA 750 250
200 1 CA 250 350
200 1 NY 1000 700
200 1 MA 500 100
200 1 NJ 750 1100

WE WANT A REPORT AS SHOWN BELOW...

STATE CID SID PRIOR_CID PRIOR_SID
----- --- --- --------- ---------
AK 200 300
cA 250 350 500 200
NY 1000 700 1000 350
MA 500 100 750 250
NJ 750 1000

If you would notice that AK is not present in current "Job" so current "CID" / "SID" is NULL but it was present in the previous "Job" so there are entries in PRIOR_CID / PRIOR_SID.

Its opposite for NJ.

Could anyone help me out with a query for the same. Would really appreciate a help. I have attched the above so that you have a look.

Thanks.
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