A
A
Alexey Sannikov2016-10-09 12:57:20
MySQL
Alexey Sannikov, 2016-10-09 12:57:20

How to display the number of rows 0 if there are none in the selection?

For the standings, you need to make a view (view) of all the defeats of the team.
I have 16 teams, of which one team has never lost, the rest have lost at least once. At the request below, I display those teams that lost, that is, 15 pieces.
How can you also display the team that has no defeats and so that its value is 0?

select `vw_games`.`ID_TEAM` AS `ID_TEAM`,count(`vw_games`.`ID_TEAM`) AS `Losses` from `test`.`vw_games` where (`vw_games`.`RESULT` < 0) group by `vw_games`.`ID_TEAM`

`vw_games`.`RESULT` < 0 is the value if there are more goals conceded than scored

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wkololo_4ever, 2016-10-09
@wkololo_4ever

SELECT (SELECT COUNT(*) FROM vw_games AS g WHERE g.ID_TEAM=t.ID_TEAM AND `vw_games`.`RESULT` < 0)
FROM Teams AS t
ps. Teams is your team table, do you have it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question