Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Stuart's answer shows you how to get the sum of the column, but I just want to note that:</p> <pre><code>...WHERE drivers LIKE '%jill%'... </code></pre> <p>will return any event with a driver whose name contains the letters 'jill'.</p> <p>Secondly, this database design doesn't seem to be normalized. You have driver names and route names repeated. If you normalize the database and have something like:</p> <p><b>participant</b></p> <pre> id | name | role </pre> <p><b>event</b></p> <pre> id | date | route_id | description | executed </pre> <p><b>route</b></p> <pre> id | name | distance </pre> <p><b>participant_event</b></p> <pre> id | participant_id | event_id </pre> <p>then it would be a lot easier to work with the data.</p> <p>Then if you wanted to implement a user search, you could make the query:</p> <pre><code>SELECT id FROM participant WHERE name LIKE '%jill%' AND role='driver'; </code></pre> <p>Then if the query returns more than one result, let the user/application choose the correct driver <i>and then</i> run a <code>SELECT SUM</code> like Stuart's query:</p> <pre><code>SELECT SUM(r.distance) FROM route r JOIN event e ON e.route_id=r.id JOIN participant_event pe ON e.id=pe.event_id JOIN participant p ON pe.participant_id=p.id WHERE p.id=?; </code></pre> <p>Otherwise, the only way to ensure that you're only getting the total distance driven by <b>one</b> driver is to do something like this (assuming <code>drivers</code> is comma-delimited):</p> <pre><code>...WHERE LCASE(drivers)='jill' OR drivers LIKE 'jill, %' OR drivers LIKE '%, jill' OR drivers LIKE '%, jill,%'; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload