According to a comment in the code (components/columns/userstats/plugin.class.php), Juan borrowed the logic and code for how to calculate the Course dedication time column from the Course Dedication block https://moodle.org/plugins/block_dedication.
On the plugin page this is outlined as:
<< How dedication time is estimated?
Time is estimated based in the concepts of Session and Session duration applied to Moodle's log entries:
- Click: every time that a user access to a page in Moodle a log entry is stored.
- Session: set of two or more consecutive clicks in
which the elapsed time between every pair of consecutive clicks does not
overcome an established maximum time.
- Session duration: elapsed time between the first and the last click of the session. >>
There is no SQL per se in the code, it's all PHP doing math on the data from the logs.
See also discussion forum here: https://moodle.org/mod/forum/discuss.php?d=109487 for more on the details of the calculations.