Sunday, April 19, 2009

Test solutions :

Test solutions :

Tables :
teachers(teacher_id,teacher_name)
courses(course_id,teacher_id,num_of_students)
students(roll_no,stu_name)
stu_courses(roll_no,course_id)

(a) Teachers not teaching any courses :
Select teacher_name from teachers where teacher_id not in (select distinct(teacher_id) from courses);
OR
Select teacher_name from teachers left join courses ON(teachers.teacher_id = courses.teacher_id) where course_id is NULL;
 
(b) Students not taking any courses :
Similar to part (a).

(c) Teachers taking maximum courses :
select a.teacher_name as 'Teacher', a.teacher_id as 'Teacher Id', count(b.course_id) as 'Num of Courses' 
from teachers a
inner join courses b on a
.teacher_id = b.teacher_id
group by b.teacher_id
order
by count(b.course_id) desc
limit
1
OR
mysql> select teachers.teacher_name,tmp1.teacher_id,tmp1.cnt from (select max(tm
p.cnt) as tmpMax from (select teacher_id,count(teacher_id) as cnt from courses g
roup by teacher_id) as tmp) as tmp2,(select teacher_id,count(teacher_id) as cnt
from courses group by teacher_id) as tmp1,teachers where tmp1.cnt = tmp2.tmpMax
and teachers.teacher_id = tmp1.teacher_id;

(d) Students taking maximum courses :
similar to part (c)

(e) names of teachers teaching maximum number of students :

mysql> select max(tmp1.sum1) from (select teacher_id,sum(num_students) as sum1 f
rom courses group by teacher_id) as tmp1;

Sunday, April 5, 2009

Normalization

Misc

1. Vim : Decrement number : Ctrl-X

2. Flex datagrid automatic sort :
someDataGrid.dispatchEvent
(
new DataGridEvent
(
DataGridEvent.HEADER_RELEASE,
false,
true,
0, // The zero-based index of the column to sort in the DataGrid object's columns array.
null,
0,
null,
null,
0
)
);
3. Vim - Adding text before or after visually selected block(rectangle) :

Suppose you have selected a rectangle (using Ctrl-v), you can insert text in front of it by typing I (switch to insert mode) and inserting your text. As soon as you leave the insert mode, the text will be added to all the other selected lines. Use A to enter text after the selection.

Thursday, April 2, 2009

Ejecting the CD Drive with PHP

Soruce


<?php

//create an instance of Windows Media Player

$mp = new COM("WMPlayer.OCX");

//ejects the first cd-rom on the drive list

$mp->cdromcollection->item(0)->eject();



?>

Blog Archive