gpt4 book ai didi

mysql错误代码: 1052 with Zend_Db

转载 作者:行者123 更新时间:2023-11-29 13:56:43 24 4
gpt4 key购买 nike

我有 2 个表

1 =“问题历史记录”

2 =“问题历史状态”

“issue_history_id”是两个表中的列名称。

“issue_history”中的 PK 和“issue_history_status”中的 FK

这是我的查询

$sql = $this->_db->select()
->from(array('ih' => 'issue_history'),array('COUNT(issue_history_id) as tot','DATE(date_created)AS date'))
->join(array('ihs' => 'issue_history_status'),'ih.issue_history_id = ihs.issue_history_id');

但它给了我错误

Error Code : 1052 Column 'issue_history_id' in field list is ambiguous

这是我的完整代码

public function getDataForGraph($sd,$ed,$issues,$os,$pf,$model,$version){

$sql = $this->_db->select()
->from(array('ih' => 'issue_history'),array('COUNT(issue_history_id) as tot','DATE(date_created)AS date','issue_history_id'))
->join(array('ihs' => 'issue_history_status'),'ih.issue_history_id = ihs.issue_history_id');



if(Engine::notEmpty($sd) && $sd != 'sd' && SG_Support_Engine::notEmpty($ed) && $ed != 'ed'){
$sql->where('DATE(ih.date_created) >= ?',$sd );
$sql->where('DATE(ih.date_created) <= ?',$ed );
}
if(Engine::notEmpty($issues) && $issues != 'issues'){
$issues = implode(',', $issues);
$sql->where('ihs.issue_id IN('.$issues.')');
}

if(Engine::notEmpty($os) && $os != 'os'){
$sql->where('ih.phone_service_os IN (?)',$os );
}

if(Engine::notEmpty($pf) && $pf != 'pf'){
$sql->where('ih.phone_service_device IN (?)',$pf );
}

if(Engine::notEmpty($model) && $model != 'model'){
$sql->where('ih.phone_service_model IN (?)',$model );
}

if(Engine::notEmpty($version) && $version != 'ver'){
$sql->where('ih.phone_service_version IN (?)',$version );
}

$sql->group('DATE(ih.date_created)');
$sql->order('DATE(ih.date_created)');

echo $sql->__toString(); exit;

return $sql->query()->fetchAll();

}

最佳答案

COUNT(issue_history_id)

该字段同时存在于两个表中,因此存在歧义。您还需要提及表名称才能正常工作。您想要统计哪个issue_history_id

COUNT(ih.issue_history_id)

或者

COUNT(ihs.issue_history_id)

关于mysql错误代码: 1052 with Zend_Db,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15739903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com