INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Combine 1 row into 2

Combine 1 row into 2

(OP)
Hi,
I have a statement where I'm trying to combine the data of two rows into one.  My data has to do with crash circumstances.  I am selecting the cicumstance and the accident no.  Circumstance '04' and '05' are the same.  I want to combine all the instances where there is a circumstance '04' and '05' with the same accident number.  Since I'm combining them, I then only want to count that accident one time.  Below is the code I have so far any suggestions would be greatly appreciated.

CODE

SELECT QO05DR_VH_CONT_CIRC  ,  COUNT(DISTINCT a.QO01ACCIDENT_NO)
FROM XTECH.TR10TBACCIDENT AS a  
JOIN XTECH.TR10TBVEHICLE_CIRCUMSTANCES AS vc ON vc.FK_QO01ACCIDENT_NO = a.QO01ACCIDENT_NO
WHERE (QO01ACCIDENT_YEAR = '2008' OR QO01ACCIDENT_YEAR = '2009' OR QO01ACCIDENT_YEAR = '2010' )
AND (QO01LONG_OR_SHORT_FORM = 'L' OR QO01LONG_OR_SHORT_FORM = 'S')
AND (QO01SUBMIT_AGENCY_ORI = 'xxxxxxxxx' OR QO01MUNICIPALITY = 'xxxx')

GROUP BY QO05DR_VH_CONT_CIRC

RE: Combine 1 row into 2

You could use the comcept of inline views here:

SELECT ...........
FROM
(SELECT .........  FROM .........) TEMP1,
(SELECT .........  FROM .........) TEMP2
ON TEMP1.QO01ACCIDENT_NO = TEMP2.QO01ACCIDENT_NO

where you can define the temp sets to generate 1 row for each QO01ACCIDENT_NO
  

Ties Blom
 
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close