有一個問題我已經張貼關於在另一篇文章中這一問題的問題,但我想嘗試更具體的在這裏使用數據表庫笨
所以我一直在使用笨與https://github.com/IgnitedDatatables/Ignited-Datatables/wiki/Function-Reference庫這裏下面的查詢
<?php
public function GetQuery(){
$this->datatables->select('tablessc.Name As region,p.name As name,tabled.test As test,
MAX(CASE WHEN p.id= p.cid and flavor = 2 THEN \'Pass\' ELSE \'Fail\' end) as \'Pass\'
')
->from('drinks p');
$this->datatables->join('tableb ', 'tableb.id=p.pid','inner');
$this->datatables->join('tablec','tablec.TerritoryId=tablec.TerritoryId','inner');
$this->datatables->join('tabled','tablec.AccountId=tablec.AccountId','inner');
$this->datatables->join('tables','d.AccountId = tabless.AccountId ','inner');
$this->datatables->join('tablessc','tablesc.Code = p.region and sc.CodeGroup =\'Region\'','inner');
$this->datatables->where('region >','0');
$this->datatables->where('p.location','0');
$this->datatables->group_by('tablessc.Name');
$this->datatables->group_by('p.id');
$this->datatables->group_by('p.name');
$this->datatables->group_by('atabled.test');
echo $this->datatables->generate();
}
?>
好了,所以如果我上運行的Microsoft SQL此查詢我沒有得到任何錯誤,我得到了我想要的結果,但如果我叫從頁面此功能,它會給我一個錯誤
Error Number: 42000
[Microsoft][SQL Server Native Client 10.0][SQL Server]Column 'drinks.region' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
SELECT * FROM drinks p INNER JOIN.....
只是爲了說明這裏爲什麼是錯誤顯示sql做一個選擇* 我試圖採取最大聚合函數,它仍然在做同樣的錯誤。 擺脫此錯誤的唯一方法是取出聚合函數MAX和group by子句。哪一個不是我想要的查詢。其他任何人都會遇到與圖書館有關的問題?謝謝