need SQL help (Oracle)

Status
Not open for further replies.

soup

Smack-Fu Master, in training
55
Here's what I have so far:

update students
set semester=
(select
(case when stu.registered_date>=sem.fall_start_date
and stu.registered_date<=sem.fall_end_date then 'FALL' else 'WINTER' end
)
from students stu, semesters sem)

However, oracle is stating I'm returning too many rows.

I tried using the 'from' keyword in the update statement but this version of oracle doesn't seem to support it.
 

htranou

Seniorius Lurkius
29
(select
(case when stu.registered_date>=sem.fall_start_date
and stu.registered_date<=sem.fall_end_date then 'FALL' else 'WINTER' end
)
from students stu, semesters sem)

that's a cartesian product, so it will return 1 line per student x semester.

I'm not sure what's the structure of your semesters table (and don't know how your semesters are made...)

but you only need something like:

Code:
update students stu
set semester=
(select
sem.something ?
from semesters sem
where stu.registered_date between sem.semester_start_date and semester.semester_end_date)

first match the correct semester, then select whatever you want to put in your semester column.

I'm still a bit lost on your semester table. What are the fall_* columns supposed to mean?
 

soup

Smack-Fu Master, in training
55
htranou":1lrv1oh4 said:
(select
(case when stu.registered_date>=sem.fall_start_date
and stu.registered_date<=sem.fall_end_date then 'FALL' else 'WINTER' end
)
from students stu, semesters sem)

that's a cartesian product, so it will return 1 line per student x semester.

I'm not sure what's the structure of your semesters table (and don't know how your semesters are made...)

but you only need something like:

Code:
update students stu
set semester=
(select
sem.something ?
from semesters sem
where stu.registered_date between sem.semester_start_date and semester.semester_end_date)

first match the correct semester, then select whatever you want to put in your semester column.

I'm still a bit lost on your semester table. What are the fall_* columns supposed to mean?

The fall columns are just of the 'SQL Date' type, the official start date (say 09-01-2011) of the semester for the school, and the official fall end date of the semester for the school (say 12-31-2011). The registered date is of the Oracle SQL date type when the student registered.

The registered dates are when the student signed up for an extra corricular activity, not for a class. The actual column names are different, and the table layout is a bit different, but for purposes here I tried to make it a little easier to understand.
 
Status
Not open for further replies.