MySQL - Finding how much duplicates are inside the same table given -


considering have following 2 sets of rows (same type) in clause:

a   b 1   1 2   2 3   4 

i need find how many in b example, given table above, 66% since 2 out of 3 numbers in b

another example:

a   b 1   1 2   2 3   4     5     3 

would give 100% since of numbers in in b

here tried myself: (doesn't work on test cases..)

drop procedure if exists getproductsbydate; delimiter // create procedure getproductsbydate (in d_given date) begin select      product,     count(*) 'total number',     (select              (select count(distinct part) products product=b.product) - count(*)                     products b2                     b2.sop < b.sop , b2.part != b.part) 'new parts',              concat(round((select              (select count(distinct part) products product=b.product) - count(*)                     products b2                     b2.sop < b.sop , b2.part != b.part)/count(distinct part)*100, 0), '%') 'share new'     products b     b.sop < d_given group product;  end//  delimiter ; call getproductsbydate (date("2018-01-01")); 

thanks.

naming tables ta , tb respectively try (test made on mssql , mysql @ moment)

select round(sum(perc) ,4)as perc_tot (     select distinct ta.id , 1.00/ (select count(distinct id) ta) perc     ta      exists ( select distinct id tb  tb.id=ta.id)     ) c; 

output first sample data set:

perc_tot 0,6667 

output second sample data set:

perc_tot 1,0000 

update (i made original 2 tables, thinking @ solution). 1 single table (is same former query): (i used id1 column , id2 column b)

select round(sum(perc) ,4)as perc_tot (     select distinct ta.id1 , 1.00/ (select count(distinct id1) ta) perc     ta      exists ( select distinct id2 ta tb  tb.id2=ta.id1)     ) c; 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -