Tema Informatica Medicala

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Breban Florentina Bogdana

TIM

TEMA INFORMATICA MEDICALA


COD:
# Baza de date utilizata:

CREATE DATABASE IF NOT EXISTS infmed05;


use infmed05;

#Creare tabel:

CREATE TABLE IF NOT EXISTS test1


(id int primary key auto_increment not null,
gender varchar(6),
age smallint(3),
treatmenttype varchar(10),
time1 date,
viruslevel1 float(10,9),
time2 date,
viruslevel2 float(10,9),
otherdisease varchar(20)) ;

# Populare tabel:

LOAD DATA LOCAL INFILE 'C:/test1.csv' INTO TABLE test1


FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n';
Breban Florentina Bogdana
TIM

# Cerinte
#1) Cati pacienti sunt femei si cati barbati sunt?

SELECT COUNT(gender) FROM test1 WHERE gender='female';


SELECT COUNT(gender) FROM test1 WHERE gender='male';

# 2) Porniti de la ideea ca pacientii care au “otherdisease” ce incepe cu litera “l” sau “k” sunt din
Bucuresti; cati pacienti sunt din Bucuresti?

SELECT COUNT(otherdisease) FROM test1 WHERE otherdisease LIKE 'l%' OR otherdisease LIKE
'k%';

#3) Acceptand ca regula de la nr. 2 este reala, adaugati o coloana, numita 'city' si populati-o
conform regulii. Coloana sa fie de tip caracter, cu un camp, valori 'Bucuresti' sau 'Alte orase';

ALTER TABLE test1


ADD city varchar(15);
UPDATE test1 SET city='Bucuresti' WHERE otherdisease LIKE 'l%' OR otherdisease LIKE 'k%';
UPDATE test1 SET city='Alte orase' WHERE city IS NULL;

# 4) Scrieti o comanda care sa numere cati pacienti sunt din Bucuresti. La fel pentru numarul de
pacienti din alte orase.

SELECT COUNT(city) FROM test1 WHERE city='Bucuresti';


SELECT COUNT(city) FROM test1 WHERE city='Alte orase';
Breban Florentina Bogdana
TIM

# 5) Care este varsta maxima a pacientilor (sex masculin). Dar a pacientelor (sex feminin) ?

SELECT MAX(age) FROM test1 WHERE gender='female';


SELECT MAX(age) FROM test1 WHERE gender='male';

# 6) Creati un tabel cu 4 coloane: 'Gen', 'Varsta medie', 'Varsta minima', 'Varsta maxima'.

CREATE TABLE test1varste


(gen varchar(6),
varstamed float(5,5),
varstamax int(2),
varstamin int(2));

# 7) Calculati varsta medie a pacientelor si a pacientilor.

SELECT AVG(age) FROM test1;


SELECT AVG(age) FROM test1 WHERE gender='female';
SELECT AVG(age) FROM test1 WHERE gender='male';

# 8) Calculati media diferentei dintre “viruslevel2” – “viruslevel1” pe fiecare “treatmenttype”.


Cum ati pondera-o si cu timpul de tratament?

ALTER TABLE test1


ADD diffviruslevel float(20,10);
UPDATE test1 SET `diffviruslevel`=`viruslevel2`-`viruslevel1` WHERE `diffviruslevel` IS NULL;

SELECT AVG(`diffviruslevel`) FROM test1 WHERE `treatmenttype`='placebo';


Breban Florentina Bogdana
TIM

SELECT AVG(`diffviruslevel`) FROM test1 WHERE `treatmenttype`='drug1';


SELECT AVG(`diffviruslevel`) FROM test1 WHERE `treatmenttype`='drug2';

# 9) Modificati tabela “test1” astfel:


# - creati tabelele “tPacient”, “tGen”, “tTratament” si “tAlteboli”;
# - populati aceste tabele cu informatiile din tabela “test1”;
# - stabiliti relatiile corecte (references) intre noile tabele.
# - cati pacienti sufera de fiecare “otherdisease” ?

CREATE TABLE IF NOT EXISTS tGen(


id_gen int PRIMARY KEY AUTO_INCREMENT not null,
gender varchar(6));

CREATE TABLE IF NOT EXISTS tTratament(


id_tratament int PRIMARY KEY AUTO_INCREMENT not null,
treatmenttype varchar (10));

CREATE TABLE IF NOT EXISTS tAlteboli(


id_alteboli int PRIMARY KEY AUTO_INCREMENT not null,
otherdisease varchar (20));

CREATE TABLE IF NOT EXISTS tPacient(


id_pacient int PRIMARY KEY AUTO_INCREMENT not null,
age smallint(3),
id_gen int,
Breban Florentina Bogdana
TIM

id_tratament int,
id_alteboli int,
INDEX(id_gen),
INDEX(id_tratament),
INDEX(id_alteboli),
FOREIGN KEY (id_gen) REFERENCES tGen(id_gen),
FOREIGN KEY (id_tratament) REFERENCES tTratament(id_tratament),
FOREIGN KEY (id_alteboli) REFERENCES tAlteboli(id_alteboli));

CREATE TABLE IF NOT EXISTS test1_copy(


id int PRIMARY KEY AUTO_INCREMENT not null,
gender varchar(6),
age smallint (3),
treatmenttype varchar(10),
time1 time,
viruslevel float,
time2 time,
viruslevel2 float,
otherdisease varchar(20));

INSERT INTO tGen (gender)


SELECT gender FROM test1;

INSERT INTO tTratament (treatmenttype)


SELECT treatmenttype FROM test1;

INSERT INTO tAlteboli (otherdisease)


Breban Florentina Bogdana
TIM

SELECT otherdisease FROM test1;

INSERT INTO tPacient (age)


SELECT age FROM test1;

SELECT count(*) FROM tAlteboli WHERE otherdisease LIKE 'l%';


SELECT count(*) FROM tAlteboli WHERE otherdisease LIKE 'k%';
SELECT count(*) FROM tAlteboli WHERE otherdisease LIKE 'm%';

# 10) Pentru un anumit “otherdisease” (la alegere), exportati cateva rezultate statistice:
# - cati pacienti au varsta pana in 50 de ani;
# - care dintre sexe (feminin sau masculin) are media de varsta cea mai ridicata; dar cea mai
scazuta ?

SELECT count(*) FROM test1 WHERE(age<50) AND otherdisease LIKE 'm%';

SELECT V.gender, V.average FROM (SELECT gender, AVG(age) average FROM test1 WHERE
otherdisease='muscular disorder' GROUP BY gender) AS V
WHERE average=(SELECT MAX(C.average) FROM (SELECT gender, AVG(age) average FROM test1
WHERE otherdisease='muscular disorder' GROUP BY gender) AS C);

SELECT V.gender, V.average FROM (SELECT gender, AVG(age) average FROM test1 WHERE
otherdisease='muscular disorder' GROUP BY gender) AS V
WHERE average=(SELECT MIN(C.average) FROM (SELECT gender, AVG(age) average FROM test1
WHERE otherdisease='muscular disorder' GROUP BY gender) AS C);

You might also like