我这里有一个奇怪的问题.. 我正在使用codeigniter for PHP,我正在使用一个名为datatables的库。您可以在此链接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 Server Native Client 10.0][SQL Server]Column 'country' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
SELECT *
FROM FROM drinks p
INNER JOIN tableb ON tableb.id=p.pid
INNER JOIN tablec ON tablec.TerritoryId=tablec.TerritoryId
INNER JOIN tabled ON tablec.AccountId=tablec.AccountId
INNER JOIN tables ON d.AccountId = tabless.AccountId
INNER JOIN tablessc ON tablesc.Code = p.region
and sc.CodeGroup ='Region'
WHERE region > '0'
AND p.location = '0'
GROUP BY tablessc.Name
,p.id
,p.name
,atabled.test
问题在于,当我只想选择我要求的列时,为什么要尝试选择所有列。我得到错误(聚合函数)的原因是因为它试图选择所有列
另请注意,如果我将此查询放在microsoft sql server上的相同结构中,我不会收到错误