Sunteți pe pagina 1din 3

#install.

packages("DBI")
library(DBI)
install.packages("RPostgreSQL")
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="SalaFitness", user="postgres", password="914cnhall
")
rs <- dbSendQuery(con, "select * from facturi")
dbGetQuery(con,"SELECT SUM(ValoareFact) AS Valoarea_facturilor_pentru_clientul10
07
FROM facturi f
where idclient='1007'" )

dbGetQuery(con,"select distinct angajati.functie, e2010.e_2010,e2011.e_2011,e201


2.e_2012,e2013.e_2013,e_total.total
from angajati
left outer join
( select functie, count(idangajat) as e_2010
from angajati
where extract(year from dataangajare)=2010
group by functie )
e2010 on e2010.functie=angajati.functie
left outer join
( select functie, count(idangajat) as e_2011
from angajati
where extract(year from dataangajare)=2011
group by functie )
e2011 on e2011.functie=angajati.functie
left outer join
( select functie, count(idangajat) as e_2012
from angajati
where extract(year from dataangajare)=2012
group by functie )
e2012 on e2012.functie=angajati.functie
left outer join
( select functie, count(idangajat) as e_2013
from angajati
where extract(year from dataangajare)=2013
group by functie )
e2013 on e2013.functie=angajati.functie
left outer join
( select functie, count(idangajat) as total
from angajati
where extract(year from dataangajare) between 2010 and 2013
group by functie )
e_total on e_total.functie=angajati.functie
where extract(year from dataangajare) between 2010 and 2013
order by 1")
dbGetQuery(con, "SELECT Distinct Idfactura , Denprod, pretunitar
FROM liniifacturi lf INNER JOIN produse p ON lf.idproduse=p.idproduse
Where PretUnitar=

(SELECT max(pretunitar) FROM liniifacturi)")


library(ggplot2)
install.packages("rJava")
sales = dbGetQuery(con, "SELECT NUmeprenumecl, count (distinct idproduse) as NrP
rodCumparate
FROM clienti c
INNER JOIN facturi f on c.idclient=f.idclient
INNER JOIN liniifacturi lf on f.idfactura=lf.idfactura
group by NumePrenumeCL")
hist(sales$nrprodcumparate, col="red")
dotchart(sales$nrprodcumparate,labels=row.names(sales),cex=.7,
main="Produse cumparate per client",
xlab="produse per client")
sapply(sales$nrprodcumparate, max, na.rm=TRUE)
valorifacturi = dbGetQuery(con, "Select valoarefact from facturi")
sapply(valorifacturi, max, na.rm=TRUE)
sapply(valorifacturi, min, na.rm=TRUE)
sapply(valorifacturi, mean, na.rm=TRUE)
sapply(valorifacturi, sd, na.rm=TRUE)
sapply(valorifacturi, var, na.rm=TRUE)
sapply(valorifacturi, range, na.rm=TRUE)
summary(valorifacturi)
install.packages("psych")
library(psych)
describe(valorifacturi)
sedinte = dbGetQuery(con, "select numeprenumeangajat, count(idsedinta) as nrsedi
nte
from sedintaantrenor inner join angajati on sedintaantrenor.idantreno
r=angajati.idangajat
group by numeprenumeangajat")
hist(sedinte$nrsedinte, col="blue")
raport = dbGetQuery(con, "select distinct denechpament, e2009.e_2009,e2010.e_201
0,e2010.e_2010,e_total.total
from inventariere i inner join echipamente e on i.idechipament=e.idechipament
left outer join
( select i.idechipament, count(nrinventar) as e_2009
from echipamente e inner join inventariere i on e.idechipament=i.idec
hipament
where extract(year from dataachizitionarii)=2009
group by i.idechipament )
e2009 on e2009.idechipament=e.idechipament
left outer join
( select i.idechipament, count(nrinventar) as e_2010
from echipamente e inner join inventariere i on e.idechipament=i.idec
hipament
where extract(year from dataachizitionarii)=2010
group by i.idechipament )
e2010 on e2010.idechipament=e.idechipament
left outer join
( select i.idechipament, count(nrinventar) as e_2011
from echipamente e inner join inventariere i on e.idechipament=i.idec

hipament
where extract(year from dataachizitionarii)=2011
group by i.idechipament )
e2011 on e2011.idechipament=e.idechipament
left outer join
( select i.idechipament, count(nrinventar) as total
from echipamente e inner join inventariere i on e.idechipament=i.idec
hipament
where extract(year from dataachizitionarii) between 2009 and 2011
group by i.idechipament )
e_total on e_total.idechipament=e.idechipament
where extract(year from dataachizitionarii) between 2009 and 2011
order by 1")
rating = dbGetQuery(con, "
SELECT idantrenor, avg(rATING) as notamedie
FROM rating
group by idantrenor
ORDER BY 2 desc
limit 5")
dotchart(rating$notamedie,labels=row.names(sales),cex=.7,
main="Note medii",
xlab="rating/antrenor")
greutate = dbGetQuery(con, "Select greutate from masurari")
summary(greutate)
masurari = dbGetQuery(con, "select *from masurari")
install.packages("coin")
install.packages("survival")
install.packages("splines")
library(coin)
masurari = dbGetQuery(con, "select umeri,talie,biceps,greutate,masamusculara,mas
agrasime from masurari")
masurari
boxplot(masurari, ylab="masura", xlab="tip masurare", col="red")
stmasurari = stack(masurari)
names(stmasurari)<-c("masura", "tip")
stmasurari
av1 = aov(masura~tip, data=stmasurari)
summary(av1)
tk = TukeyHSD(av1)
tk
plot(tk)