The first is session, in the db it is stored as 1 or 2.
afternoon,morning (values 1, 2)
Language, also stored as 1, 2.
English, Chinese (values 1, 2)
Class number which has values K1,K2,3,4,G...etc. This list is long and changes from time to time.
For example a student who goes to class morning,english,K2 is known as class MEK2 (values 2,1,K2 in his record in the database)
I want to know how many different classes there are in the school.
This much of the sql I know...
step 1
First convert from numeric values to alpha
Expand|Select|Wrap|Line Numbers
- CASE WHEN Session=1 THEN 'E' ELSE 'C' END
- CASE WHEN Language=1 THEN 'A' ELSE 'M' END
Combine the three parts into one alpha value eg MEK2, AC4, etc
step 3
Do steps 1,2 for all of the student records but take only the distinct values. (I can then display this list in a dropdown box.)
Can anyone help me with the sql to extract the information?
I think the sql might be something like this but obviously it does not work.
Expand|Select|Wrap|Line Numbers
- select concat(sess,lang,classnum) as clas from studentstbl inner join where studentstbl.sess, studentstbl.lang in
- (select case when session=1 then 'a' else 'm' end as sess, case when language=1 then 'm' else 'c' end as lang from studentstbl)