-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlAssignment1.sql
64 lines (45 loc) · 1.99 KB
/
SqlAssignment1.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- Database for online cunsultation and therapy website.
create database online_consultaion;
create table doctor(doc_id integer primary key ,
doc_name varchar(50) not null ,
specialization varchar(50));
create table patient(patient_id integer primary key,
patient_name varchar(50) not null,
email varchar(60) default "",
phone bigint not null);
create table appointments(id integer primary key ,
doc_id integer not null ,
patient_id integer not null,
appointment_date date ,
appointment_time time,
status integer not null,
foreign key(doc_id) references doctor(doc_id),
foreign key(patient_id) references patient(patient_id));
create table review(id integer primary key,
doc_id integer not null,
patient_id integer not null,
rating integer default 1,
comment varchar(200),
date date);
-- 2nd question
#1 selecting all columns from the Contact table where active_flag=1
select * from contacts where active_flag=1;
#2 Deactivation of contacts who are opted out
update contacts set active_flag=0 where opt_out=1;
#3 Deleting all the contacts who have the company name as ‘ABC’
delete from contacts where company='ABC';
#4Inserting a new row with id as 658, name as ‘mili’, email as ‘[email protected]’,
#the company as ‘DGH’, active flag as 1, opt-out flag as 1
insert into contacts(Id ,Email ,fname ,lname , company , Active_flag ,opt_out)
values(658, 'mili' ,null,'[email protected]' ,'DFG',1,1);
#5 Pulling out the unique values of the company column
select distinct(company) from contacts;
#6 Updating name “mili” to “niti”.
update contacts set fname='niti' where fname='mili';
-- 3 Question
/* Writing a SQL query to find those customers with a grade less than 100.
It should return cust_name, customer city, grade, salesman, and salesman city.
The result should be ordered by ascending customer_id.m */
select c.cust_name , c.city , c.grade ,s.name, s.city from customer c
join saleman s on c.cust_id = s.cust_id
where c.grade<100 order by c.cust_id asc;