Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *
- FROM clutches
- WHERE clutch_breeding_pair = 2 ORDER BY clutch_laid_date DESC
- $stmt = $dbh->query("SELECT * FROM clutches WHERE clutch_breeding_pair = '$breedingPairID' ORDER BY clutch_laid_date DESC");
- $stmt->setFetchMode(PDO::FETCH_ASSOC);
- $row_count = $stmt->rowCount();
- $row = $stmt->fetch();
- SELECT c.clutch_breeding_pair,
- ifnull(AVG(datediff(c.next_clutch_laid_date,c.clutch_laid_date)/7),0) average_weeks
- FROM (
- SELECT c1.clutch_breeding_pair,
- c1.clutch_laid_date,
- min(c2.clutch_laid_date) next_clutch_laid_date
- FROM clutches c1
- left join clutches c2
- on c2.clutch_laid_date > c1.clutch_laid_date
- and c2.clutch_breeding_pair = c1.clutch_breeding_pair
- WHERE c1.clutch_breeding_pair = 2
- GROUP BY
- c1.clutch_breeding_pair,
- c1.clutch_laid_date
- ) c
- GROUP BY
- c.clutch_breeding_pair
- SELECT clutch_breeding_pair,
- truncate((datediff(max(clutch_laid_date), min(clutch_laid_date)) /
- IF (count(*) > 1, count(*) - 1, 1) / 7), 4) AS average_weeks
- FROM clutches
- -- WHERE clutch_breeding_pair = 2 -- filter by clutch_breeding_pair
- GROUP BY clutch_breeding_pair
- -- HAVING average_weeks > 0; -- remove 0 value rows
- WHERE clutch_breeding_pair = 2 -- filter by clutch_breeding_pair
- HAVING average_weeks > 0; -- remove 0 value rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement