A
A
Alexey Sannikov2016-10-09 11:01:47
MySQL
Alexey Sannikov, 2016-10-09 11:01:47

How to specify the value 0 instead of NULL?

Please help me with the request. I want to make a league table. The essence of the problem is that I need the total number of defeats of the team to be displayed in the views, and everything is displayed well, but ... If the team has no defeats, then this line simply does not appear, that is, as if the NULL value is attached. I need to display 0, not NULL.

select `vw_игры`.`id_команды` AS `id_команды`,count(`vw_игры`.`id_команды`) AS `поражения` from `test`.`vw_игры` where (`vw_игры`.`забили` < `vw_игры`.`пропустили`) group by `vw_игры`.`id_команды`

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SimBioT19, 2016-10-09
@SimBioT19

SELECT IFNULL(count(`vw_игры`.`id_команды`), 0) as `поражения`

IMHO names like "team_id" are a complete nightmare, why didn't team_id suit you?
At least don't mix Cyrillic and Latin! Then my head hurts...

Z
Zhainar, 2016-10-09
@zhainar

try to display the field like

case when count(`vw_игры`.`id_команды`) = null then 0 else count(`vw_игры`.`id_команды`) end AS `поражения`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question