Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL query - aggregating by date
    primarykey
    data
    text
    <p>I seem to have some hard time figuring out the right query for my problem, any help will be appreciated.</p> <p>I have <strong>2</strong> tables :</p> <p><strong>PatientExercise</strong> <code>(PatientID,ExerciseID,StartDate,EndDate)-first 3 are PK</code></p> <p><strong>PatientHistory</strong> <code>(PatientID,ExerciseID,CompletionDate) -all 3 are PK</code></p> <p>I'm trying to build 2 queries. </p> <p>The first needs to return the exercise completion percentage for a given Patient for a week (by days), and the second query should do the same for 3 months(by weeks).</p> <p>for example :</p> <p>PatientExercise: there cant be any overlap dates in this table(PatientExercise)</p> <pre><code>PatientID ExerciseID StartDate EndDate --------------------------------------------- 111 13 2013-04-28 2013-08-28 111 14 2013-04-28 2013-08-28 111 16 2013-04-28 2013-05-07 111 17 2013-05-09 2013-08-28 222 13 2013-04-28 2013-08-28 222 14 2013-04-28 2013-08-28 . . . </code></pre> <p>PatientHistory</p> <pre><code>PatientID ExerciseID CompletionDate ------------------------------------ 111 13 2013-04-28 111 13 2013-05-05 111 14 2013-05-05 111 13 2013-05-06 111 14 2013-05-06 111 13 2013-05-07 111 14 2013-05-07 111 16 2013-05-07 111 13 2013-05-08 </code></pre> <p>for patientID 111 with a giving start of the week date of 2013-05-05 query 1 results:</p> <pre><code>day Completion ------------------------------- 2013-05-05 66% -&gt;&gt; there are 3 exe's that has to be done on this date (13,14,16) and according to history he did only 2 (13,14) so 2/3 = 66% 2013-05-06 66% 2013-05-07 100% 2013-05-08 50% 2013-05-09 0% 2013-05-10 0% 2013-05-11 0% </code></pre> <p>and the same for second query but instead of day --> week.</p> <p>Thank you! </p>
    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.
 

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