Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Hello All,

I have a table "Staff" and a related table "Lesson_Observations".  A Staff record has many Lesson_Observation records.  Each lesson observation is attributed a score.

I have a working ExecuteSQL calculation that finds the average of all lesson observations scores for staff in a specific Faculty ("English" in the example below) and only where the Staff record has the attribute "Active".

Let ( [ $query = "SELECT AVG(L.obCritAverageVal) 
FROM Lesson_Observation L INNER JOIN Staff S 
ON L.FK_StaffCode = S.PK_StaffCode
WHERE S.Fk_FacName = ? AND S.Status = ?"

; $result = ExecuteSQL ( $query
; "" ; ""
; "English"; "Active")

]; $result
)

Each Lesson_Observation record has an attribute "Observation_Date".  Is there a way I can modify the query above to find the average of only the MOST RECENT lesson_observation for each member of staff in a Faculty where that member is staff is still Active?

Thank you!

Ben

Try

ExecuteSQL ( "
  SELECT AVG ( O.score ) 
  FROM Observations O

  JOIN Staff S On S.id = O.id_staff

  WHERE 
    S.faculty = ? AND
    S.status = ? AND
    O.TS = ( 
      SELECT MAX (O2.TS)
      FROM Observations O2
      WHERE O2.id_staff = O.id_staff
      )
  " ; "" ; "" ; "English" ; "Active" 
)

which you obviously need to adapt to your nomenclature

Edited by eos

  • Author

Genius!  This is neat!

I had worked around it by sorting the relationship in descending date order and then adding a calculated field Last_Ob_Score to the Staff table which = observation score from the Observation table - then doing a simple ExecuteSQL from the Last_Ob_Score field.

No need for the extra database overhead with your query.

Thanks

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.