1 Matching Annotations
  1. Jan 2023
    1. SELECT HORSE_ID, SUM(PURSE), COUNT(*) AS NUM_RACES FROM RACE_RESULT GROUP BY HORSE_ID;

      okay what i'm missing here is that the race_result table I think groups rows by race, not by horse. So each horse can have multiple races.

      The above statements asks the dbms to find each race (row) with a specific horse_id, and then average certain column values from all the rows corresponding to the same horse_id. The average is then to be output as a new row containing a single horse id, the sum of that horses earnings across all race rows, the COUNT(*) statement is then used to count how many rows in the horse table had a specific horse id.So really the query is requesting a table with

      horse_id | (earnings sum from race_result rows with horse_id) | (number of race result rows featuring horse_id)