MySQL counting without count function? -


database: tennis, ie tennis club.

table discussed: penalties

columns: paymentno, amount, playerno

task:

  • classify penalty amounts high, medium, low - done !
  • then, count number of penalties in low category - need help.

how do part 2 without using count function ? possible ?

sql query 1:

use tennis;  select tennis.penalties.paymentno,         tennis.penalties.amount,         tennis.penalties.playerno,        case           when playerno >= 0 ,  playerno <= 40 'low'          when playerno > 40 ,  playerno < 80 'medium'          when playerno > 80 'high'        end tennis.penalties; 

thanks.

sum(playerno >= 0 , playerno <= 40) count_penalties_in_low 

or

sum(case when playerno >= 0 , playerno <= 40 1 else 0 end) count_penalties_in_low 

so technically summarize 1s, in fact equals count

ps:

playerno >= 0 ,  playerno <= 40 

can rewritten to

playerno between 0 , 40 

pps:

playerno = 80 isn't covered condition

ppps: i'd write case in way:

   case       when playerno <= 40 'low'      when playerno <= 80 'medium'                          else 'high'    end 

pppps: solution without functions (concept)

select @i:=@i+1, other_columns table, (select @i:=0) x 

and having @i can count want

but terrible solution in case


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -