Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. SELECT *
  2. FROM clutches
  3. WHERE clutch_breeding_pair = 2 ORDER BY clutch_laid_date DESC
  4.  
  5. $stmt = $dbh->query("SELECT * FROM clutches WHERE clutch_breeding_pair = '$breedingPairID' ORDER BY clutch_laid_date DESC");
  6. $stmt->setFetchMode(PDO::FETCH_ASSOC);
  7. $row_count = $stmt->rowCount();
  8. $row = $stmt->fetch();
  9.  
  10. SELECT c.clutch_breeding_pair,
  11. ifnull(AVG(datediff(c.next_clutch_laid_date,c.clutch_laid_date)/7),0) average_weeks
  12. FROM (
  13. SELECT c1.clutch_breeding_pair,
  14. c1.clutch_laid_date,
  15. min(c2.clutch_laid_date) next_clutch_laid_date
  16. FROM clutches c1
  17. left join clutches c2
  18. on c2.clutch_laid_date > c1.clutch_laid_date
  19. and c2.clutch_breeding_pair = c1.clutch_breeding_pair
  20. WHERE c1.clutch_breeding_pair = 2
  21. GROUP BY
  22. c1.clutch_breeding_pair,
  23. c1.clutch_laid_date
  24. ) c
  25. GROUP BY
  26. c.clutch_breeding_pair
  27.  
  28. SELECT clutch_breeding_pair,
  29. truncate((datediff(max(clutch_laid_date), min(clutch_laid_date)) /
  30. IF (count(*) > 1, count(*) - 1, 1) / 7), 4) AS average_weeks
  31. FROM clutches
  32. -- WHERE clutch_breeding_pair = 2 -- filter by clutch_breeding_pair
  33. GROUP BY clutch_breeding_pair
  34. -- HAVING average_weeks > 0; -- remove 0 value rows
  35.  
  36. WHERE clutch_breeding_pair = 2 -- filter by clutch_breeding_pair
  37.  
  38. HAVING average_weeks > 0; -- remove 0 value rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement