CREATE TABLE no_inconcl_aux_tmp (
    source varchar(255) binary unique not null,
    no smallint(6) not null
);
CREATE TABLE no_concl_hyp_tmp (
    source varchar(255) binary unique not null,
    no smallint(6) not null
);
CREATE TABLE no_hyp_tmp (
    source varchar(255) binary unique not null,
    no smallint(6) not null
);

INSERT INTO no_inconcl_aux_tmp
SELECT source, COUNT(h_occurrence)
FROM refObj
WHERE
  h_position='http://www.cs.unibo.it/helm/schemas/schema-helm#InConclusion'
  OR h_position='http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion'
GROUP BY source;

INSERT IGNORE INTO no_inconcl_aux_tmp
SELECT source, 0
FROM refObj
GROUP BY source;

INSERT INTO no_concl_hyp_tmp
SELECT source, COUNT(DISTINCT h_occurrence)
FROM refObj
WHERE NOT (h_position="http://www.cs.unibo.it/helm/schemas/schema-helm#InBody")
GROUP BY source;

INSERT IGNORE INTO no_concl_hyp_tmp
SELECT source, 0
FROM refObj
GROUP BY source;

INSERT INTO no_hyp_tmp
SELECT source, COUNT(DISTINCT h_occurrence)
FROM refObj
WHERE (h_position="http://www.cs.unibo.it/helm/schemas/schema-helm#MainHypothesis"
    OR h_position="http://www.cs.unibo.it/helm/schemas/schema-helm#InHypothesis")
GROUP BY source;

INSERT IGNORE INTO no_hyp_tmp
SELECT source, 0
FROM refObj
GROUP BY source;

INSERT INTO count
SELECT no_hyp_tmp.source, 
       no_inconcl_aux_tmp.no, 
       no_hyp_tmp.no, 
       no_concl_hyp_tmp.no
FROM no_hyp_tmp, no_concl_hyp_tmp, no_inconcl_aux_tmp
WHERE no_hyp_tmp.source = no_concl_hyp_tmp.source AND
      no_hyp_tmp.source = no_inconcl_aux_tmp.source;

DROP TABLE no_hyp_tmp;
DROP TABLE no_inconcl_aux_tmp;
DROP TABLE no_concl_hyp_tmp;



