このクエリを取得して1行にカウントを返すのが難しいです。 結果を示す1行異なる年とは、トランザクションが(この場合は2016のように)がない場合IFNULLクエリが2行同じ結果を返す
私は、このコードを実行異なる年間でトランザクションを挿入し、結果は同じ結果と2行で
を示しますここで私は私のプロジェクトで毎年報告書を作成しようとしている
select
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=1)AND (YEAR(date)='2017'))),0) AS `Jan`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=2)AND (YEAR(date)='2017'))),0) AS `Feb`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=3)AND (YEAR(date)='2017'))),0) AS `Mar`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=4)AND (YEAR(date)='2017'))),0) AS `Apr`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=5)AND (YEAR(date)='2017'))),0) AS `May`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=6)AND (YEAR(date)='2017'))),0) AS `Jun`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=7)AND (YEAR(date)='2017'))),0) AS `Jul`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=8)AND (YEAR(date)='2017'))),0) AS `Aug`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=9)AND (YEAR(date)='2017'))),0) AS `Sep`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=10)AND (YEAR(date)='2017'))),0) AS `Oct`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=11)AND (YEAR(date)='2017'))),0) AS `Nov`,
ifnull((SELECT COUNT(id) FROM (transaction)WHERE((Month(date)=12)AND (YEAR(date)='2017'))),0) AS `Dec`
from transaction GROUP BY YEAR(date)
コードだ、このまたはそれが動作することができます別のクエリを修正する方法はありますか?