hibernate - Making Sum result As Distinct In mysql? -
here code
select count( model.voter.voterid), sum( case when model.voter.age between :age18 , :age25 1 else 0 end) agecount , sum( case when model.voter.age between :age26 , :age35 1 else 0 end) agecount , sum( case when model.voter.age between :age36 , :age45 1 else 0 end) agecount , sum( case when model.voter.age between :age46 , :age60 1 else 0 end) agecount , sum( case when model.voter.age > :age60 1 else 0 end) agec user model model.voter.voterid in(:voterids)
i passed 21 objects showing 22 result 22 when make select count( distict model.voter.voterid)
21 toal result still 22
can make sum condition distinct? how?
select count(uservoterd0_.voter_id) col_0_0_, sum(case when voter1_.age between 18 , 25 1 else 0 end) col_1_0_, sum(case when voter1_.age between 26 , 35 1 else 0 end) col_2_0_, sum(case when voter1_.age between 36 , 45 1 else 0 end) col_3_0_, sum(case when voter1_.age between 46 , 60 1 else 0 end) col_4_0_, sum(case when voter1_.age>60 1 else 0 end) col_5_0_ user_voter_details uservoterd0_ inner join voter voter1_ on uservoterd0_.voter_id=voter1_.voter_id uservoterd0_.voter_id in (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?)
if passing in 21 user ids getting value of 22 count()
, have duplicate rows in data.
try running query see duplicates are:
select cnt, count(*), min(voterid ), max(voterid) (select voterid, count(*) cnt user u group voterid ) t group cnt order cnt desc
Comments
Post a Comment