すべての例を見つけたので、間違っていると確信しています。 私は結果を得ていますが、合計を2倍にしたり、合計を大量に複製したりしています。MySQLサブクエリはまだ2倍のSUM値を生成します
クエリは次のとおりです。
select
(st.total_cells) as 'Cells Sorted',
from abstract_freeze af
left join abstract_ejaculate_collection aec on af.ejaculate_collection_id = aec.id
left join mo_flo on aec.id = mo_flo.ejaculate_collection_id
left join sample_time st on mo_flo.id = st.mo_flo_id
left join collection_schedule cs on aec.collection_schedule_id = cs.id
left join collection_plan cp on cs.collection_plan_id = cp.id
left join sub_admission sa on cp.sub_admission_id = sa.id
left join master_admission ma on sa.master_admission_id = ma.id
left join animal on ma.animal_id = animal.id
where aec.tenant_id = 8 and date(aec.scheduled) = '2017-04-12' and sa.type = 'Sexed'
group by aec.id;
af.ejaculate_collection_id年代の繰り返しの数に基づいて、私のSUM(st.total_cells)重複そのため、同じejaculate_collection_idで複数abstract_freezeレコードが存在します。
私のクエリまたはサブクエリが正しいと思われるので、グループ化に基づいてtotal_cellsの合計が必要です。
私はどこに和が表示されません。これはあなたの全体の質問ですか? –
申し訳ありませんが、 "Cells Sorted"に焦点を当てていましたが、SUM(st.total_cells)を読み込む必要があるため、私は短縮するためにいくつかの行を削除しました。私の間違い。 –