Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 27th, 2011, 02:04 AM
marky1607 marky1607 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 1 marky1607 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 49 sec
Reputation Power: 0
Problem with multiple queries from single table

Hello everyone!

I'm pretty familliar with basics od SQL but this task gives me some hard time. I've still haven't mastered all possible commands and possibilities and that my biggest problem at the moment.

I have an original table with multiple columns (about 15 of them) and I need data from five or six of this columns but through several filters and conditions. Here's a example with columns I need:

RPT_ID TOT_AMT_KN NO_UNITS PACKAGE_TYPE AR_PPS_TP_GRP_DSC
RCDF_CARDIF_KRE 10020.94 1 KRATKOROČNI
RCDF_CARDIF_KRE 22268.76 2 KRATKOROČNI
RCDF_CARDIF_KRE 9427.10 1 GOTOVINSKI
RCDF_CARDIF_KRE 3191.85 1 KRATKOROČNI
RCDF_CARDIF_KRE 31918.54 1 GOTOVINSKI
RCDF_CARDIF_KRE 29691.67 1 GOTOVINSKI
RCDF_CARDIF_FOS 0.00 0 B GOTOVINSKI
RCDF_CARDIF_FOS 96376.25 1 B GOTOVINSKI
RCDF_CARDIF_FOS 56501.50 1 B GOTOVINSKI
RCDF_CARDIF_FOS 45349.20 1 B GOTOVINSKI
RCDF_CARDIF_FOS 210269.74 1 B GOTOVINSKI
RCDF_CARDIF_FOS 132342.16 1 B GOTOVINSKI
RCDF_CARDIF_FOS 0.00 0 B GOTOVINSKI
RCDF_CARDIF_FOS 369827.30 1 B STAMBENI

The key is that I need to segment the data into two groups by RPT_ID column. But there's a problem that some corresponding data in other columns for one value of RPT_ID (RCDF_CARDIF_FOS) exist, and for other value (RCDF_CARDIF_KRE) doesn't. For example - RPT_ID values ending in FOS have package_type values A, B or C and RPT_ID values ending in KRE don't have any value in package_type column.

Still, they need to be represented in single resulting table as shown in this screenshot from excel:

That's my first problem - how to segment the data for two values that exists in one column.

Second problem is how can I write a SELECT that will select some data from one column under one condition and put it one new resulting column. After that, I also need to select the same original column under second condition and put that data in another resulting column.

Hope you can help with some input, I know it's a lot of garbled data.

Reply With Quote
  #2  
Old December 27th, 2011, 04:30 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,355 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 4 h 25 m 19 sec
Reputation Power: 4140
Quote:
Originally Posted by marky1607
The key is that I need to segment the data into two groups by RPT_ID column.
use ORDER BY rpt_id

this will ensure that all rows with the same value in the rpt_id column are grouped together
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Problem with multiple queries from single table

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap