背景のビット: ミツバチは、それらを識別するために使用される番号付きの色のタグを受け取ります。ミツバチが多すぎるため、タグを再利用する必要があります。ただし、特定のタグが同時に使用されることはなく、ミツバチの生年月日と死亡日が記録されます。
データ構造:
TABLE: tags
id bee_id tag_date colony_id events tagged_by
=================================================================================
1 G23 2013-06-01 1 birth ET
2 Y35 2013-06-03 1 birth ET
3 G23 2013-07-01 NULL death ET
4 G23 2013-07-02 2 birth ET
5 W64 2013-07-03 1 birth ET
6 Y35 2013-07-15 NULL death ET
望ましい出力:
bee_id Status Birth Date Death Date
======================================================
G23 Dead 2013-06-01 2013-07-01
G23 Alive 2013-07-02 NULL
Y35 Dead 2013-06-03 2013-07-15
私が試したこと(そして失敗したこと)
select * from
( select *
from tags
order by tag_date
where events = "birth"
limit 1 ) as births
group by `bee_id`