2017-03-27 125 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

相关问题