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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -