Skip to content

Commit

Permalink
Update 01_SQL.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rritec authored Sep 3, 2024
1 parent de7ad17 commit e2fb121
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Notebooks/Interview Questions/01_SQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,77 @@
1. Can we get all salesmans information where dept name is Sales?

select * from emp,dept where emp.deptno=dept.deptno and dept.deptno=30 and job = 'SALESMAN'
1. Write query to get studentname,teachername,subjectname based on below data.

```sql
Create table dbo.student(
Student_ID int,
Student_Name Varchar(50),
Class int)

Create table dbo.TEACHER(
TID int,
Teacher_Name Varchar(50),
)

create table dbo.SUBJECT(
Sub_Id int,
Sub_Name Varchar(50))

create table dbo.STUDENT_SUBJECT(
Stu_Id int,
Sub_Id int,
Teacher_Id int)

Create table dbo.Student_Marks(
Student_ID int,
Sub_Id int,
Marks int,
Class int)

INSERT INTO dbo.student (Student_ID, Student_Name,Class) VALUES
(1, 'aaa',1),
(2, 'bbb',2);

INSERT INTO dbo.TEACHER (TID, Teacher_Name) VALUES
(1, 'hhh'),
(2, 'gggg');

INSERT INTO dbo.SUBJECT (Sub_Id, Sub_Name) VALUES
(1, '2maths'),
(2, 'Science');

INSERT INTO STUDENT_SUBJECT (Stu_Id, Sub_id, Teacher_Id) VALUES
(1, 1, 1),
(2, 1, 1);

INSERT INTO Student_Marks (Student_ID, Sub_Id, Marks, Class) VALUES
(1, 1, 34, 1),
(1, 2, 90, 1),
(2, 1, 55, 1),
(2, 2, 40, 1);
```
``` sql
SELECT
st.Student_Name,
T.Teacher_Name, Sb.Sub_Name, sm.Marks,
CASE
WHEN sm.Marks >= 0 and sm.Marks < 35 THEN 'Fail'
WHEN sm.Marks >= 35 and sm.Marks < 50 THEN 'Just Pass'
WHEN sm.Marks >= 50 and sm.Marks < 60 THEN 'Second Class'
WHEN sm.Marks >= 60 and sm.Marks <= 100 THEN 'First Class'
END AS Grade
FROM
STUDENT_SUBJECT ss
JOIN
STUDENT st ON st.Student_ID = ss.Stu_Id
join
TEACHER T ON T.TID = ss.Teacher_Id
join SUBJECT sb ON sb.Sub_Id = ss.Sub_id
join Student_Marks sm ON sm.Sub_Id = ss.Sub_id and sm.Student_ID = st.Student_ID
```



2.

0 comments on commit e2fb121

Please sign in to comment.