|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
As you can see, I am quite the newbie to DB design. =)
Good idea. Thanks! |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > count non-empty columns |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|