0

Unequal division = distribution

How to retrieve output with example :

CREATE TABLE yourTable 
(
     id varchar(55), 
     code int,
     count1 int,
     count2 int
);

INSERT INTO yourTable (id, code,count1,count2)
VALUES
    ('no-29', 12345, 4, 1),
    ('no-29', 32346, 4, 1)

always count1-count2 and results distribution between others rows with same id: example : 4-1 = 3 and 3 distribution between 12345, 32346

I want too distribution 1,1 and 1,0 order by id,code(because 3 is odd and if even => 1,1 and 1,1 => countdistribute for codes is 2,2 )

description : if count1 is odd and count of rows is even then all rows can`t count1 equal ( if count1=3 and count of rows=2 then 3/2=1.3 mean one of rows can countdistribute= 2 and another row can countdistribute= 1 and sum 1+2=3 Unequal division)

Output :

id         code    countdistribute
----------------------------------
'no-29'    12345        2
'no-29'    32346        1

Browse other questions tagged or ask your own question.