You are on page 1of 6

--1. A.

S-A CREAT Tabelul CT_ABONAT


CREATE TABLE CT_ABONAT
(
ID integer NOT NULL primary key,
Nume varchar2(25), Prenume varchar2(25),
Nr_de_telefon varchar2(10) NOT NULL
);
--2. A.
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022152524');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'Anastasia', '022023036');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022362123');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022190778');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022345522');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022210976');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022092908');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022999587');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'022901774');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME,
'Constatin', '022152524');

NR_DE_TELEFON) VALUES ('1', 'Anachii', 'Eugen',


NR_DE_TELEFON) VALUES ('2', 'Matvienco',
NR_DE_TELEFON) VALUES ('3', 'Jacota', 'Liubovi',
NR_DE_TELEFON) VALUES ('4', 'Leah', 'Andrei',
NR_DE_TELEFON) VALUES ('5', 'Barba', 'Natalia',
NR_DE_TELEFON) VALUES ('6', 'Turcan', 'Ala',
NR_DE_TELEFON) VALUES ('7', 'Tolmaci', 'Andrei',
NR_DE_TELEFON) VALUES ('8', 'Apostol', 'Ion',
NR_DE_TELEFON) VALUES ('9', 'Panarin', 'Dumitru',
NR_DE_TELEFON) VALUES ('10','Burlacu',

SELECT *FROM CT_ABONAT


--1. B. S-A CREAT TABELUL CT_ACHITARI
CREATE TABLE CT_ACHITARI
(
ID_Achitarii integer NOT NULL primary key,
ID integer NOT NULL, Suma DECIMAL(5,2) NOT NULL,
Data_achitarii date NOT NULL
);
-- 2. B.
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'15.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'06.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'06.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'20.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'11.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'19.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'15.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'300,00', '09.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'08.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'145,50', '15.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'191,00', '15.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'100,21', '15.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'15.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'19.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'276,68', '21.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii)
'180,80', '15.01.2014');

VALUES ('1', '1', '141,01',


VALUES ('2', '2', '150,70',
VALUES ('3', '4', '6,00',
VALUES ('4', '3', '1,45',
VALUES ('5', '6', '50,14',
VALUES ('6', '4', '200,93',
VALUES ('7', '5', '7,67',
VALUES ('8', '10',
VALUES ('9', '7', '150,40',
VALUES ('10', '8',
VALUES ('11', '9',
VALUES ('12', '7',
VALUES ('13', '7', '71,01',
VALUES ('14', '3', '90,02',
VALUES ('15', '4',
VALUES ('16', '1',

INSERT INTO CT_ACHITARI(ID_Achitarii,


'367,00', '12.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'15.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'09.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'18.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'23.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'14.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'250,98', '16.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'149,89', '11.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'125,76', '18.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'23.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'44,40', '14.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'25.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'15.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'146,41', '18.02.2014');
select
select
select
/*DROP

*from
*from
*from
TABLE

ID, Suma, DATA_achitarii) VALUES ('17', '10',


ID, Suma, DATA_achitarii) VALUES ('18', '2', '22,14',
ID, Suma, DATA_achitarii) VALUES ('19', '2', '14,31',
ID, Suma, DATA_achitarii) VALUES ('20', '6', '19,09',
ID, Suma, DATA_achitarii) VALUES ('21', '5', '10,01',
ID, Suma, DATA_achitarii) VALUES ('22', '5', '11,11',
ID, Suma, DATA_achitarii) VALUES ('23', '8',
ID, Suma, DATA_achitarii) VALUES ('24', '3',
ID, Suma, DATA_achitarii) VALUES ('25', '1',
ID, Suma, DATA_achitarii) VALUES ('26', '9', '02,01',
ID, Suma, DATA_achitarii) VALUES ('27', '10',
ID, Suma, DATA_achitarii) VALUES ('28', '9', '92,99',
ID, Suma, DATA_achitarii) VALUES ('29', '8', '96,01',
ID, Suma, DATA_achitarii) VALUES ('30', '6',

CT_ACHITARI;
CT_SERVICII
CT_SERV_ABONAT
CTA_LOC3.CT_ACHITARI;*/

/*Sa ne afiseze numarul achitarilor zilnice si in ce suma*/


/*select a.ID AS ABONAT,
from CT_ABONAT a, CT_ACHITARI b*/
SELECT *FROM CT_ACHITARI
--3. SELECTEAZA TOATE CANTITATEA ACHITARILOR SI TOTALA GRUPATA PE ZILE
SELECT B.DATA_ACHITARII, SUM(B.SUMA)AS SUMA_TOTAL,COUNT(*) AS NR_DE_ACHITARI
FROM CT_ACHITARI B
GROUP BY b.data_achitarii
ORDER BY B.DATA_ACHITARII
/*Sa ne afiseze fiecare abonat ce suma a achitat in total si in medie
SELECT *FROM CT_ACHITARI
SELECT SUM(b.suma)
FROM CT_ACHITARI b
SELECT SUM(b.suma)
FROM CT_ACHITARI b
GROUP BY b.ID
SELECT b.id AS ID_ABONAT, SUM(b.suma)
FROM CT_ACHITARI b
GROUP BY b.ID
SELECT b.id AS ID_ABONAT, SUM(b.suma), a.nume ||' '|| a.PRENUME AS NUME_PRENUME_ABONAT
FROM CT_ACHITARI b, CT_ABONAT a
where b.id = a.id
GROUP BY b.ID, a.nume ||' '|| a.PRENUME*/
--4. SELECTEAZA CE SUMA A ACHITAT fiecare abonat in total si in medie
SELECT b.id AS ID_ABONAT, SUM(b.suma)AS SUMA_TOTALA, avg(b.suma)AS SUMA_MEDIE, a.nume ||'
'|| a.PRENUME AS NUME_PRENUME_ABONAT
FROM CT_ACHITARI b, CT_ABONAT a
where b.id = a.id

GROUP BY b.ID, a.nume ||' '|| a.PRENUME


/* Sa ne afiseze suma totala pe luni a fiecarui abonat.
SELECT *FROM CT_ACHITARI
SELECT SUM(B.SUMA)
FROM CT_ACHITARI B
GROUP BY B.DATA_ACHITARII*\
substr(ttoc(start),1,8) as calldata,count(*)*/
--5. Selecteaza ce sume s-au achitat lunar
SELECT TO_CHAR(B.DATA_ACHITARII,'YYYY.MM')AS DATA_TOTALE, SUM(B.SUMA)AS SUMA_TOTAL
FROM CT_ACHITARI B
GROUP BY TO_CHAR(B.DATA_ACHITARII,'YYYY.MM')
ORDER BY TO_CHAR(B.DATA_ACHITARII,'YYYY.MM') ASC
/*--4
SELECT a.nume ||' '|| a.PRENUME AS NUME_PRENUME_ABONAT, A.NR_DE_TELEFON, B.DATA_ACHITARII,
B.SUMA
FROM CT_ABONAT A, CT_ACHITARI B
WHERE b.id = a.id and B.SUMA<'183' and b.data_achitarii<'18.01.2014'
ORDER BY b.data_achitarii asc*/
--6. Selectati toti abonatii care au achitat in total mai putin de 100 lei
SELECT *FROM CT_ACHITARI
SELECT b.id AS ID_ABONAT, SUM(b.suma)AS SUMA_TOTALA, a.nume ||' '|| a.PRENUME AS
NUME_PRENUME_ABONAT
FROM CT_ACHITARI b, CT_ABONAT a
where b.id = a.id --AND b.suma<100
GROUP BY b.ID, a.nume ||' '|| a.PRENUME
Having SUM(b.suma)<100
ORDER BY SUM(b.suma) ASC

-- 5. Adaug abonatii, inregistrari in Tabelul CT_ABONAT


INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'024485795');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'025156896');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'024325456');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'027265447');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'027155063');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'024669847');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'024486325');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'024486325');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'024687999');
INSERT INTO CT_ABONAT(ID, NUME, PRENUME, NR_DE_TELEFON)
'024367810');

VALUES ('11','Balaur', 'Aurel',


VALUES ('12','Rotaru', 'Tatian',
VALUES ('13','Pavalachi', 'Ana',
VALUES ('14','Codreanu', 'Pavel',
VALUES ('15','Tverdohleb', 'Aura',
VALUES ('16','Pruteanu', 'Denis',
VALUES ('17','Onachii', 'Anatol',
VALUES ('18','Onachii', 'Maria',
VALUES ('19','Cebanu', 'Cristina',
VALUES ('20','Torgai', 'Ionela',

select *FROM CT_ABONAT


--a.grupezi pe raion
/*select A.ID, SUM(a.nr_de_telefon)AS TEL_RAIONAL, a.nume ||' '|| a.PRENUME AS
NUME_PRENUME_ABONAT
from CT_ABONAT A
where A.NR_DE_TELEFON NOT LIKE '022%'
GROUP BY A.ID, a.nume ||' '|| a.PRENUME
ORDER BY SUM(a.nr_de_telefon)
*/

--b. suma achitata totala


INSERT INTO CT_ACHITARI(ID_Achitarii,
'56,08', '18.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'89,67', '10.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'13.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'10,08', '09.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'156,08', '18.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'22,68', '20.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'533,08', '18.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'153,08', '18.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'569,00', '18.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'18.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'33,98', '15.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'63,08', '19.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'03,08', '27.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'11,11', '13.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'29,10', '15.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'100,78', '10.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'230,94', '13.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'500,50', '1.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'6011,11', '03.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'11,11', '31.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'55,66', '03.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'123,00', '31.01.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'87,45', '28.02.2014');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'3596,00', '17.12.2013');
INSERT INTO CT_ACHITARI(ID_Achitarii,
'89,34', '31.01.2014');

ID, Suma, DATA_achitarii) VALUES ('31', '11',


ID, Suma, DATA_achitarii) VALUES ('32', '11',
ID, Suma, DATA_achitarii) VALUES ('33', '11', '0,08',
ID, Suma, DATA_achitarii) VALUES ('34', '14',
ID, Suma, DATA_achitarii) VALUES ('35', '14',
ID, Suma, DATA_achitarii) VALUES ('36', '19',
ID, Suma, DATA_achitarii) VALUES ('37', '16',
ID, Suma, DATA_achitarii) VALUES ('38', '16',
ID, Suma, DATA_achitarii) VALUES ('39', '12',
ID, Suma, DATA_achitarii) VALUES ('40', '16', '4,08',
ID, Suma, DATA_achitarii) VALUES ('41', '17',
ID, Suma, DATA_achitarii) VALUES ('42', '12',
ID, Suma, DATA_achitarii) VALUES ('43', '12',
ID, Suma, DATA_achitarii) VALUES ('44', '12',
ID, Suma, DATA_achitarii) VALUES ('45', '13',
ID, Suma, DATA_achitarii) VALUES ('46', '13',
ID, Suma, DATA_achitarii) VALUES ('47', '13',
ID, Suma, DATA_achitarii) VALUES ('48', '20',
ID, Suma, DATA_achitarii) VALUES ('49', '20',
ID, Suma, DATA_achitarii) VALUES ('50', '20',
ID, Suma, DATA_achitarii) VALUES ('51', '19',
ID, Suma, DATA_achitarii) VALUES ('52', '19',
ID, Suma, DATA_achitarii) VALUES ('53', '19',
ID, Suma, DATA_achitarii) VALUES ('54', '18',
ID, Suma, DATA_achitarii) VALUES ('55', '11',

--7.Selecteaza ce sume de bani s-au achitat pe fiecare raion


select substr(a.nr_de_telefon,1,4), SUM(b.suma)AS SUMA_TOTALA
from CT_ABONAT A, CT_ACHITARI B
where A.NR_DE_TELEFON NOT LIKE '022%' and a.id=b.id_achitarii
GROUP BY substr(nr_de_telefon,1,4)
ORDER BY substr(nr_de_telefon,1,4)ASC
-varianta finala
select --substr(a.nr_de_telefon,1,4),
CASE
WHEN substr(a.nr_de_telefon,1,4)='0243'
WHEN substr(a.nr_de_telefon,1,4)='0244'
WHEN substr(a.nr_de_telefon,1,4)='0246'
WHEN substr(a.nr_de_telefon,1,4)='0251'
WHEN substr(a.nr_de_telefon,1,4)='0271'
WHEN substr(a.nr_de_telefon,1,4)='0272'
END
,SUM(b.suma)AS SUMA_TOTALA
from CT_ABONAT A, CT_ACHITARI B

THEN
THEN
THEN
THEN
THEN
THEN

'Causeni'
'Calarasi'
'Edinet'
'Donduseni'
'Ocnita'
'Soldanesti'

where A.NR_DE_TELEFON NOT LIKE '022%' and a.id=b.id_achitarii


GROUP BY substr(nr_de_telefon,1,4)
ORDER BY SUM(b.suma) ASC
/*
SELECT COUNT(*) AS TotalCount,
SUM(CASE WHEN Color = 'Red' THEN 1 ELSE 0 END) AS RedCount,
SUM(CASE WHEN Color = 'Black' THEN 1 ELSE 0 END) AS BlackCount
FROM SalesLT.Product*/
--select substr(nr_de_telefon,1,4) from CT_ABONAT
/*SELECT b.id AS ID_ABONAT, SUM(b.suma)AS SUMA_TOTALA, avg(b.suma)AS SUMA_MEDIE, a.nume ||'
'|| a.PRENUME AS NUME_PRENUME_ABONAT
FROM CT_ACHITARI b, CT_ABONAT a
where b.id = a.id
GROUP BY b.ID, a.nume ||' '|| a.PRENUME*/
--6.TABELA CT_SERVICII
CREATE TABLE CT_SERVICII
(
ID_SERVICIU integer NOT NULL primary key,
TIP_SERVICIU VARCHAR2(25) NOT NULL
);
SELECT *FROM CT_SERVICII
INSERT INTO CT_SERVICII(ID_SERVICIU, TIP_SERVICIU)
INSERT INTO CT_SERVICII(ID_SERVICIU, TIP_SERVICIU)
INSERT INTO CT_SERVICII(ID_SERVICIU, TIP_SERVICIU)
INSERT INTO CT_SERVICII(ID_SERVICIU, TIP_SERVICIU)
select *from CT_SERVICII
SELECT * CT_SERVICII
--7 TABELA
CREATE TABLE CT_SERV_ABONAT
(
ID_SERV_AB integer NOT NULL primary key,
ID_SERVICIU integer NOT NULL,
ID integer NOT NULL
);
SELECT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT

*FROM CT_SERV_ABONAT
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,
INTO CT_SERV_ABONAT(ID_SERV_AB,

ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,

VALUES
VALUES
VALUES
VALUES

ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID
ID

)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)

('1',
('2',
('3',
('4',

'TELEVIZIUNE');
'INTERNET');
'TEL_MOBILA');
'TEL_FIXA');

VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES

('1','1','3');
('2','1','1');
('3','2','1');
('4','4','4');
('5','3','1');
('6','1','10');
('7','4','5');
('8','1','7');
('9','2','7');
('10','1','9');
('11','3','9');
('12','4','9');
('13','4','6');
('14','3','5');
('15','2','10');
('16','2','2');
('17','3','2');
('18','1','2');
('19','4','2');
('20','4','8');
('21','4','10');
('22','3','3');
('23','3','6');
('24','2','8');
('25','1','12');
('26','2','12');
('27','3','14');
('28','4','13');
('29','1','16');

INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT

INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO

CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,
CT_SERV_ABONAT(ID_SERV_AB,

ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,
ID_SERVICIU,

ID
ID
ID
ID
ID
ID
ID
ID
ID

)
)
)
)
)
)
)
)
)

VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES

('30','2','20');
('31','3','19');
('32','4','20');
('33','1','15');
('34','2','17');
('35','3','17');
('36','4','18');
('37','1','18');
('38','2','15');

--ADAUGAM PUNCTUL 9
SELECT *FROM CT_ACHITARI
ALTER TABLE CT_ACHITARI ADD ID_SERV_AB INTEGER;
INSERT INTO CT_ACHITARI(ID_Achitarii, ID, Suma, DATA_achitarii, ID_SERV_AB) VALUES ('56',
'1', '60,40', '15.12.2013' '4' );
/*SELECT a.*,S.ID_SERV_AB, S.* FROM CT_ACHITARI A, CT_SERV_ABONAT S WHERE A.ID=S.ID
SELECT *FROM CT_SERV_ABONAT
SELECT *FROM CT_ACHITARI*/
SELECT TRUNC(dbms_random.value(1,5)) FROM DUAL;
UPDATE CT_ACHITARI SET ID_SERV_AB =TRUNC(dbms_random.value(1,5))
/*MERGE INTO CT_ACHITARI A USING CT_SERV_ABONAT S ON (A.ID=S.ID)
WHEN MATCHED THEN
UPDATE SET A.ID_SERV_AB =S.ID_SERV_AB */
/* MERGE INTO TABLE_NAME USING table_reference ON (condition)
WHEN MATCHED THEN
UPDATE SET column1 = value1 [, column2 = value2 ...]
WHEN NOT MATCHED THEN
INSERT (column1 [, column2 ...]) VALUES (value1 [, value2 ...) ;*/
--10. selecteaza suma totala pentru fiecare serviciu in parte
select SUM(b.suma)AS SUMA_TOTALA, C.TIP_SERVICIU
from CT_ACHITARI b, CT_SERVICII C
where B.ID_SERV_AB=C.ID_SERVICIU
GROUP BY C.ID_SERVICIU, C.TIP_SERVICIU
ORDER BY SUM(b.suma) ASC