1. What does ending your query with “limit 100” do and when should you use this statement?

  1. What data will this query return? {{{select * from biograph, members

where matgrp = grp and biograph.sname = members.sname and sex = 'M' and status = 0 and dcause = 0 and statdate = date order by matgrp, pid; }}}

  1. What data will this query return? {{{select * from biograph, members

where biograph.matgrp = members.grp and biograph.sname = members.sname and biograph.sex = 'M' and biograph.status = 0 and biograph.dcause = 0 and biograph.statdate = members.date order by biograph.matgrp, biograph.pid; }}}

  1. What data will this query return? {{{select *
    • from biograph
      • join members on (biograph.matgrp = members.grp and
        • biograph.sname = members.sname)
      • where biograph.sex = 'M' and
        • biograph.status = 0 and biograph.dcause = 0 and biograph.statdate = members.date
        order by biograph.matgrp, biograph.pid;

}}}

  1. What data will this query return? {{{-- This is an illustrative query used in the Babase Quiz

-- It is fiendishly tricky so pay close attention! SELECT *

}}}

  1. What are the pros and cons of the various queries above. Which do you prefer?

  1. Write a query that shows each date that each male offspring spent in his maternal group -- the one codified in the GROUPS table. {{{SELECT biograph.matgrp, biograph.sname, members.date
    • FROM biograph
      • JOIN members ON (members.grp = biograph.matgrp AND
        • members.sname = biograph.sname)
      WHERE biograph.sex = 'M' ORDER BY biograph.matgrp, biograph.sname, members.date;

}}}

  1. Write a query that returns the number of days that each male offspring spends in his maternal group -- the one codified in the GROUPS table. {{{SELECT biograph.matgrp, biograph.sname, COUNT(*) AS daysingrp
    • FROM biograph
      • JOIN members ON (members.grp = biograph.matgrp AND
        • members.sname = biograph.sname)
      WHERE biograph.sex = 'M' GROUP BY biograph.matgrp, biograph.sname ORDER BY biograph.matgrp, biograph.sname;

}}}

-- table we create will go away automatically when the transaction -- rolls back. BEGIN;

-- Create an intermediate table in my personal schema to query for the real results. SELECT biograph.matgrp, biograph.sname, COUNT(*) AS daysingrp

SELECT foobar.matgrp, COUNT(*), AVG(foobar.daysingrp)

-- Undo all the changes we made to the database, i.e. forget -- about the intermediate table we created. ROLLBACK; }}}

-- sql session is done executing. SELECT biograph.matgrp, biograph.sname, COUNT(*) AS daysingrp

SELECT foobar.matgrp, COUNT(*), AVG(foobar.daysingrp)

}}}

-- as if they were a real table. SELECT foobar.matgrp, COUNT(*), AVG(foobar.daysingrp)

}}}

SELECT foobar.matgrp, COUNT(*), AVG(foobar.daysingrp), STDDEV(foobar.daysingrp)

}}}

  1. What are the four things that are wrong with using the above queries to analyze how long males stay in their maternal group before dispersing? I.e. What's wrong with the way the questions above were framed and what data peculiarities get in the way of obtaining a good answer? Answer: 1) Some of the males die before they disperse. 2) Some of the groups fission before the juvenile males disperse so the males "move" to another group as the result of fission. 3) Some groups were not under continuous observation and when there is no observation for long enough individuals are automatically placed in the unknown group. 4) As of the end of the most recent data entered some of the males are not old enough to have dispersed.

Wiki content based upon work supported by the National Science Foundation under Grant Nos. 0323553 and 0323596. Any opinions, findings, conclusions or recommendations expressed in this material are those of the wiki contributor(s) and do not necessarily reflect the views of the National Science Foundation.