select max(ts_done) from iiabmdb.without_exp_sample;
select min(ts_done) from iiabmdb.without_exp_sample;
select count(*) from iiabmdb.without_exp_sample;

select distinct s_id from iiabmdb.without_exp_result where ts > 0;
select s_id, max(ts) as max_ts from iiabmdb.without_exp_result where ts > 0 group by s_id order by max_ts;
select e_id, count(id) as count, max(max_ts) as max_max_ts from iiabmdb.without_exp_sample as a 
inner join (select s_id, max(ts) as max_ts from iiabmdb.without_exp_result where ts > 0 group by s_id) as b 
on a.id = b.s_id
group by e_id
order by count desc;

select e_id, count, max_max_ts, dct_lst_init_remove_firm_prod from iiabmdb.without_exp_experiment as a
inner join 
(select e_id, count(id) as count, max(max_ts) as max_max_ts from iiabmdb.without_exp_sample as a 
inner join (select s_id, max(ts) as max_ts from iiabmdb.without_exp_result where ts > 0 group by s_id) as b 
on a.id = b.s_id
group by e_id) as b
on a.id = b.e_id
where count > 10
order by count desc;

select s_id, max(ts) as max_ts from iiabmdb.without_exp_result where ts > 0 group by s_id;
select * from iiabmdb.without_exp_result order by s_id limit 0,50;
select s_id, COUNT(DISTINCT id_firm, id_product) as n_disrupt_firm_prod from iiabmdb.without_exp_result group by s_id;
select * from 
(select s_id, COUNT(DISTINCT id_firm, id_product) as n_disrupt_firm_prod_sample from iiabmdb.without_exp_result group by s_id) as count_disrupt_firm_prod_sample 
where n_disrupt_firm_prod_sample > 1;

select e_id, n_disrupt_sample, total_n_disrupt_firm_prod_experiment, dct_lst_init_disrupt_firm_prod from iiabmdb.without_exp_experiment as experiment
inner join (
select e_id, count(id) as n_disrupt_sample, sum(n_disrupt_firm_prod_sample) as total_n_disrupt_firm_prod_experiment from iiabmdb.without_exp_sample as sample 
inner join (
select * from 
(select s_id, COUNT(DISTINCT id_firm, id_product) as n_disrupt_firm_prod_sample from iiabmdb.without_exp_result group by s_id
) as count_disrupt_firm_prod_sample 
where n_disrupt_firm_prod_sample > 1
) as  disrupt_sample
on sample.id = disrupt_sample.s_id
group by e_id
) as disrupt_experiment
on experiment.id = disrupt_experiment.e_id
order by n_disrupt_sample desc, total_n_disrupt_firm_prod_experiment desc
limit 0, 95; # 20% of 475 experiment