Last active
August 29, 2015 14:07
-
-
Save jeremywrnr/4191017026efbfc3a37d to your computer and use it in GitHub Desktop.
some fun sql query highlights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION heartrate() | |
RETURNS TABLE(nodeid integer, hrbpm numeric) AS | |
$BODY$ | |
DECLARE r record; | |
BEGIN | |
FOR r IN SELECT DISTINCT wampum.nodeid FROM wampum ORDER BY nodeid | |
LOOP | |
RETURN QUERY SELECT wampum.nodeid, wampum.hrbpm FROM wampum | |
WHERE wampum.nodeid=r.nodeid ORDER BY id DESC LIMIT 1; | |
END LOOP; | |
RETURN; | |
END | |
$BODY$ | |
LANGUAGE 'plpgsql' ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with early as ( | |
select sid, min(timestamp) | |
from thinkcspy_log, courses | |
where courses.course_name = thinkcspy_log.course_id | |
and courses.inst_type = 'highschool' | |
group by sid | |
) | |
select thinkcspy_log.sid, toc.chapter_id | |
from early, thinkcspy_log, toc | |
where early.sid = thinkcspy_log.sid | |
and early.min = thinkcspy_log.timestamp | |
and toc.div_id = thinkcspy_log.div_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select sid, min(timestamp), max(timestamp) | |
from thinkcspy_log, courses | |
where courses.course_name = thinkcspy_log.course_id | |
and courses.inst_type = 'highschool' | |
group by sid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment