--SARC Downloads

CREATE TABLE IF NOT EXISTS ${usageStatsDB}.sarc_downloads_stats_tmp
(`source` string,
`repository_id` string,
`result_id` string,
`date`	string,
`count` bigint,
`openaire`	bigint);

INSERT INTO ${usageStatsDB}.sarc_downloads_stats_tmp
SELECT s.source, d.id AS repository_id,
ro.id as result_id, CONCAT(CAST(YEAR(`date`) AS STRING), '/',
LPAD(CAST(MONTH(`date`) AS STRING), 2, '0')) AS `date`, s.count, '0'
FROM ${usageRawDataDB}.sushilog s, ${statsDB}.datasource_oids d, ${statsDB}.result_pids ro
WHERE d.oid LIKE CONCAT('%', s.repository, '%') AND d.id like CONCAT('%', 'sarcservicod', '%')
AND s.rid=ro.pid AND ro.type='Digital Object Identifier' AND s.metric_type='ft_total' AND s.source='SARC-OJS';

