library(RMySQL) library(tidyverse) yhendus<-dbConnect(dbDriver("MySQL"), user='mart', password='ajutine1234', host= 'localhost', dbname='mart' ) paring<-dbSendQuery(yhendus, "SELECT classificator_code, MAX(if(film_type_id= 6, kogus, 0)) AS dokfilm, MAX(if(film_type_id=56, kogus, 0)) AS mangufilm FROM (SELECT classificator_code, film_type_id, COUNT(*) AS kogus FROM efis_film JOIN efis_film_maker ON efis_film_maker.film_id=efis_film.id JOIN efis_film_type_rel ON efis_film_type_rel.film_id=efis_film.id WHERE efis_film_type_rel.film_type_id IN (56, 6) AND classificator_code IN ('FILM_MAKER_CINEMATOGRAPHER', 'FILM_MAKER_DIRECTOR', 'FILM_MAKER_CONTENT_EDITOR') GROUP BY classificator_code, film_type_id) AS abitabel GROUP BY classificator_code") andmed=fetch(paring, n=-1) andmed %>% select(dokfilm, mangufilm) %>% chisq.test()