
# transfer corm_datasource into cache db
create table corm_datasource like syn_delta.corm_datasource;
insert into corm_datasource 
select * from syn_delta.corm_datasource;

# create the mergeList
create table mergeList
select bioRecordKey as brKey
from syn_delta.bioRecord
join syn_delta.resource   on bioRecordResourceKey = resourceKey
left join corm_datasource on resource.serviceKey = corm_datasource.serviceKey
where (european_data_only is null	  /* analyse services without "european_data_only" flag */
       and (bioRecordCountryCode in 
			('AL', 'AD', 'AT', 'BY', 'BE', 'BA', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE',
			 'GI', 'GR', 'HU', 'IS', 'IE', 'IL', 'IT', 'LV', 'LI', 'LT', 'LU', 'MK', 'MT', 'MD', 'MC',
			 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'CS', 'SK', 'SI', 'ES', 'SE', 'CH', 'UA', 'UK', 'VA')
      		  or	(    geoLatitude between 35 and 71
  		        and geoLongitude between -10 and 60)
  	    )
      )
   or (european_data_only = 1);		 /* providers with european_data_only */

alter table mergeList
	add key (brKey);