从cakephp中的两个数据库中连接两个表

时间:2016-10-12 05:40:15

标签: php

我创建了两个db并从两个db连接两个表。查询在本地工作,但在实时服务器中不起作用,并显示错误,如

  

SQLSTATE [42000]:语法错误或访问冲突:1142 SELECT命令   拒绝用户

和我的连接查询代码:

$holiday_workings = $this->CompoffEntry->find('all', array(

            'joins' => array(
                    array(
                            'table' => 'Meds.employee_details',
                            'alias' => 'Emp_det',
                            'type'  => 'INNER',
                            'foreignKey'    => false,
                            'conditions'    => array('CompoffEntry.worked_on_period' => $holiday_period,'CompoffEntry.worked_on_date != ' => null,'CompoffEntry.employee_detail_id = Emp_det.employee_detail_id', 'Emp_det.emp_status = "A"',($department != 'all') ? 'Emp_det.department_id = '.$department : '',($roleId == 5) ? 'reporting_id = '.$user_id : ''),
                    ) 
            )
    ));

1 个答案:

答案 0 :(得分:0)

连接表格时,请尝试使用外键使您的工作更简单

print (df2.index.get_level_values('dates').month)
[2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4
 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5
 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7
 7 7 7 7 7 7 7 7]

df3 = df2.groupby([df2.index.get_level_values('count'), 
                   df2.index.get_level_values('dates').month]).size().unstack()
print (df3)
         2     3     4     5     6     7
count                                   
0      2.0  31.0  30.0   NaN   NaN   NaN
1      NaN   NaN   NaN  14.0  30.0  12.0

price_per_hour = df.price / df3.sum(axis=1)
print (price_per_hour)
0     9523.809524
1    12500.000000
dtype: float64

print (df3.mul(price_per_hour, axis=0))
                  2              3              4         5         6  \
count                                                                   
0      19047.619048  295238.095238  285714.285714       NaN       NaN   
1               NaN            NaN            NaN  175000.0  375000.0   
              7  
count            
0           NaN  
1      150000.0  

print (df3.mul(price_per_hour, axis=0).sum(axis=1))
count
0    600000.0
1    700000.0
dtype: float64

只要您的变量初始化和分配值,代码应该按预期工作。谢谢。