2017-03-27 7 views
0

私はlaravelで使用する必要があるこのクエリを持っています。私はモデルとコントローラでこれらのテーブルをどうやって使うことができないのですか?laravelで複数のテーブルを使用するには?

select mon,year, 
     combo, 
     registered, 
     forwardedbycmo, 
     clarification, 
     noaction, 
     disposed,mon_srno,undertaken 
from monthly_activities 
union 
select extract('month' from actiondate) as mon,extract('year' from actiondate) as year, 
     extract('year' from actiondate)|| '-' ||to_char(to_timestamp (extract('month' from actiondate)::text, 'MM'), 'TMMon') as combo, 
     sum(case when actioncode = '00' then 1 else 0 end) as registered, 
     sum(case when actioncode = '4T' and fromorg='CMOFF' then 1 else 0 end) as forwardedbycmo, 
     sum(case when actioncode = '4D' and fromorg='CMOFF' then 1 else 0 end) as clarification, 
     sum(case when actioncode = '10' then 1 else 0 end) as noaction, 
     sum(case when actioncode = '50' then 1 else 0 end) as disposed,null as mon_srno, 
     sum(case when actioncode = '40' and fromorg='CMOFF' then 1 else 0 end) as undertaken 

from actionhistory where extract(month from actiondate)=extract(month from current_date) 
and extract(year from actiondate)=extract(year from current_date) 
group by mon,year order by year,mon; 
"; 
+0

質問にスタックオーバーフローでクローズとしてマークすることができるように答えをマークしてください。ありがとう – Learner

+0

しかし、私は別の質問を追加する必要がありますこのクエリで問題に直面している? –

答えて

0

ヘッドスタートのためにLatest larevel Docs here を確認してください。複数のsnake_caseとしてLaravelでテーブルを定義し、sigular camelCaseでモデルを作成する必要があります。生またはLaravelメイドのいずれか、monthly_activitiesテーブル用

php artisan make:model monthlyActivity

のように...

その後、クエリを実行するためのさまざまな方法があります。

だから例えば、あなたはモデルを作成する必要があります。 いくつかの時間と労力をかけ、つづればもっと正確な質問を投稿して助けてください。 ありがとう、

+0

ありがとう私はこれを試してみるつもりです –

+0

@ニシャ・ガルグ、答えは受け入れられているとマークしてください。ありがとう – Learner

関連する問題