You are on page 1of 2

create database health_care;

--------------------------------------------
use health_care;
--------------------------------------------
create table patients (
date date,
patient_id varchar (15),
patient_name varchar (15),
age int,
weight int,
gender varchar (15),
location varchar(15),
phone_number int,
disease varchar (15),
doctor_name varchar (15),
doctor_id int);
--------------------------------------------
desc patients;
--------------------------------------------
alter table patients
rename column patient_id to pid;
--------------------------------------------
insert into patients ( date, pid, patient_name, age, weight, gender,
location, phone_number, disease, doctor_name, doctor_id)
values
(str_to_date('15-06-2019','%d-%m-%Y') ,'AP2021', 'Sarath', 67, 76
,'Male', 'chennai', 5462829 ,'Cardiac', 'Mohan', 21),
(str_to_date('13-02-2019','%d-%m-%Y') ,'AP2022', 'John', 62, 80
,'Male', 'banglore', 1234731 ,'Cancer', 'Suraj', 22),
(str_to_date('08-01-2018','%d-%m-%Y') ,'AP2023', 'Henry', 43, 65
,'Male', 'Kerala', 9028320 ,'Liver', 'Mehta', 23),
(str_to_date('04-02-2020','%d-%m-%Y') ,'AP2024', 'Carl', 56,
72 ,'Female', 'Mumbai', 9293829 ,'Asthma', 'Karthik', 24),
(str_to_date('15-09-2017','%d-%m-%Y') ,'AP2025', 'Shikar', 55, 71
,'Male', 'Delhi', 7821281 ,'Cardiac', 'Mohan', 21),
(str_to_date('22-07-2018','%d-%m-%Y') ,'AP2026', 'Piysuh', 47, 59
,'Male', 'Haryana', 8912819 ,'Cancer', 'Suraj', 22),
(str_to_date('25-03-2017','%d-%m-%Y') ,'AP2027', 'Stephen', 69, 55
,'Male', 'Gujarat', 8888211 ,'Liver', 'Mehta', 23),
(str_to_date('22-04-2019','%d-%m-%Y') ,'AP2028', 'Aaron', 75, 53
,'Male', 'Banglore', 9012192 ,'Asthma', 'Karthik', 24);
-------------------------------------------- ----------------------------
---------------- --------------------------------------------
select * from patients;
--------------------------------------------
select count(distinct pid) from patients;
--------------------------------------------
SELECT MAX(age), pid, patient_name, gender,disease FROM
patients;
--------------------------------------------
select now();
--------------------------------------------
select pid, patient_name, now() as CD from patients;
--------------------------------------------
SELECT ucase(patient_name) as new_PN, patient_name as old_PN
FROM patients;
--------------------------------------------
select patient_name, length (patient_name) as LP from patients;
--------------------------------------------
select patient_name ,
case when gender = 'Male' then 'M'
when gender= 'Female' then 'F'
end as GN
from patients;
--------------------------------------------
select concat( patient_name, ' ', doctor_name) as PDN
from patients;
--------------------------------------------
select
age,
log10(age)
from patients;
--------------------------------------------
select date,
extract(year from date) as Year
from patients;
--------------------------------------------
select
case when patient_name = doctor_name then 'null'
else patient_name end as XYZ
from patients;
-----------------------------------------------------
select age,
case when age >40 then 'yes'
else 'no'
end as Elder
from patients;
-----------------------------------------------------
select distinct doctor_name
from patients
group by 1
having count(doctor_name) >=2
-----------------------------------------------------

You might also like