mysql - How to divide two values in same column -
i trying divide "counts". requirements division values should have same batch id , carry acronym. divisor should count value "dental -nebd" , dividend should "added batch".
how can that?
here's data sample:
batch carr_acronym date count datatype 45056 arm 12/31/2014 20 added batch 45056 arm 12/31/2014 0 deleted batch 45056 arm 12/31/2014 5 dental - nedb 45055 cuu 12/31/2014 0 dental - nedb
something should work. can create temporary table join on , select need. temporary table dropped after transaction. take current table (in question) , duplicate temp table. join 2 tables (current 1 in question plus newly created temp table) based on conditions (matching batch , matching carr_acronym) , divide counts when datatypes of appropriate value.
create temporary table if not exists temptable (select * mytable); select (`a`.`count` / `b`.`count`) `result` mytable `a` inner join temptable `b` on (`a`.`batch` = `b`.`batch`) , (`a`.`carr_acronym` = `b`.`carr_acronym`) a.datatype 'added%' , b.datatype 'dental%';
Comments
Post a Comment