2017-03-27 47 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 了先機。您需要在Laravel中將您的表定義爲複數snake_case,並且模型將以歎號的camelCase創建。

因此,舉例來說,你需要創建模型:

php artisan make:model monthlyActivity

爲monthly_activities表等...

然後你有不同的方法來執行查詢,生的或Laravel製成。 花費一些時間和精力,然後如果你被困住了,發佈一個更確切的問題來獲得幫助。 謝謝,

+0

謝謝我要試試這個 –

+0

@Nisha Garg,請將答案標記爲已接受,以便可以將問題標記爲在堆積溢出時關閉。謝謝 – Learner

相關問題