Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 12th, 2004, 07:30 PM
JulieH JulieH is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 JulieH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
count non-empty columns

Hi All,

I was told this can't be done in SQL, but I want to throw it out there to get some opinions and suggestions.

I have a table CASE with 8 columns (maybe more in the future) that consists of 1 case_id column and 7 question#_id columns that looks something like this:

Code:
 case_id   question1_id   question2_id   question3_id   question4_id 
 -------   ------------   ------------   ------------   ------------ 
 cq001         q0089         q0023          q0034 
 cq002         q0045         q0021          q0024           q0034


Is there an SQL statement I can use to get the number of questions for a specific case_id? i.e. cq001 = 3 & cq002 = 4

Any help is appreciated. Thanks!

Reply With Quote
  #2  
Old May 13th, 2004, 02:38 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
Redesign. With your current model you need to add columns and change your queries if there are more than four questions for a certain case. This is against all fundamental principles for database design.

Store one question per record.

case_id ordinal question_id
--------------------------


Using this you are not limited to any number of questions.

To get the number of question for a case_id.

Code:
select count(*) from t where case_id = 4711

Reply With Quote
  #3  
Old May 13th, 2004, 12:38 PM
JulieH JulieH is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 JulieH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
As you can see, I am quite the newbie to DB design. =)
Good idea. Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > count non-empty columns


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway