Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- teams:
- -----------------------
- | team_id | team_name |
- -----------------------
- team_results:
- ----------------------------------------------------------
- | team_results_id | team_id | result_date | won (1 OR 0) |
- ----------------------------------------------------------
- SELECT *, COUNT(*)
- FROM
- (
- SELECT teams.team_id, won
- FROM teams
- INNER JOIN
- (
- SELECT team_id, won
- FROM team_results
- ORDER BY result_date DESC
- ) AS team_results ON teams.team_id = team_results.team_id
- ) AS a
- WHERE won = 0
- GROUP BY team_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement