php - Codeigniter 请求 sql 但我的代码返回错误

标签 php mysql sql-server codeigniter

我希望显示 SQL 请求的结果,但我的代码返回了一个我无法解决的错误。如果有人能帮助我,我将不胜感激。

我正在使用 Codeigniter。

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Dropdown extends CI_Controller {

    public function __construct()
    {
        parent::__construct();  
    }

    public function index()
    {   
        $data['title']='Dependent Dropdown List';
        $data['page']='index';
        $data['MANUFACTURERS'] = $this->book_model->get_author();
        $this->load->view('index', $data);
    }


    public function ctest()
    {
        $data['MODELS'] = $this->book_model->test();
        $this->load->view('ajax_get_book',$data);
    }

}
?>

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class book_model extends CI_Model {


    function __construct(){
        // Call the Model constructor
        parent::__construct();        
    }
    public function test() {   
        $lang = 6;
        $code = 533001410;

        $query = $this->db->query("SELECT DISTINCT
         IF (ART_LOOKUP.ARL_KIND IN (3, 4), BRANDS.BRA_BRAND, 
         SUPPLIERS.SUP_BRAND) AS 
         BRAND, ART_LOOKUP.ARL_SEARCH_NUMBER AS NUMBER, ART_LOOKUP.ARL_KIND,    
         ART_LOOKUP.ARL_ART_ID, DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT
         FROM       ART_LOOKUP
         LEFT JOIN BRANDS ON BRANDS.BRA_ID = ART_LOOKUP.ARL_BRA_ID
         INNER JOIN ARTICLES ON ARTICLES.ART_ID = ART_LOOKUP.ARL_ART_ID
         INNER JOIN SUPPLIERS ON SUPPLIERS.SUP_ID = ARTICLES.ART_SUP_ID
         INNER JOIN DESIGNATIONS ON DESIGNATIONS.DES_ID = 
         ARTICLES.ART_COMPLETE_DES_ID
         INNER JOIN DES_TEXTS ON DES_TEXTS.TEX_ID = DESIGNATIONS.DES_TEX_ID
         WHERE  ART_LOOKUP.ARL_SEARCH_NUMBER = '.$code.' AND    
         ART_LOOKUP.ARL_KIND 
         IN (1, 2, 3, 4) AND    DESIGNATIONS.DES_LNG_ID = '.$lang.'
         GROUP BY   BRAND,  NUMBER");
         return $query->result();
    }
}
?>

Error Number: 1055
Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dpazine.ART_LOOKUP.ARL_KIND' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

SELECT DISTINCT IF (ART_LOOKUP.ARL_KIND IN (3, 4), BRANDS.BRA_BRAND, SUPPLIERS.SUP_BRAND) AS BRAND, ART_LOOKUP.ARL_SEARCH_NUMBER AS NUMBER, ART_LOOKUP.ARL_KIND, ART_LOOKUP.ARL_ART_ID, DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT FROM ART_LOOKUP LEFT JOIN BRANDS ON BRANDS.BRA_ID = ART_LOOKUP.ARL_BRA_ID INNER JOIN ARTICLES ON ARTICLES.ART_ID = ART_LOOKUP.ARL_ART_ID INNER JOIN SUPPLIERS ON SUPPLIERS.SUP_ID = ARTICLES.ART_SUP_ID INNER JOIN DESIGNATIONS ON DESIGNATIONS.DES_ID = ARTICLES.ART_COMPLETE_DES_ID INNER JOIN DES_TEXTS ON DES_TEXTS.TEX_ID = DESIGNATIONS.DES_TEX_ID WHERE ART_LOOKUP.ARL_SEARCH_NUMBER = '.533001410.' AND ART_LOOKUP.ARL_KIND IN (1, 2, 3, 4) AND DESIGNATIONS.DES_LNG_ID = '.6.' GROUP BY
BRAND, NUMBER

Filename: C:/wamp64/www/CodeIgniter/system/database/DB_driver.php
Line Number: 691

最佳答案

您的 GROUP BY 子句不包含 SELECT 中的所有非聚合字段,例如 ART_LOOKUP.ARL_KIND、ART_LOOKUP.ARL_ART_ID、DES_TEXTS.TEX_TEXT AS ART_COMPLETE_DES_TEXT。

请参阅此链接了解更多信息...

https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html

也许可以将这些字段添加到您的 GROUP BY 中?

关于php - Codeigniter 请求 sql 但我的代码返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45872095/

相关文章:

php - 子查询或求和内求和。这是可能的?

sql - 使用表的字段值重命名 SQL 表的列

sql-server - 我应该使用什么样的 JOIN 来连接这些表?

sql - 为什么sql server中每个表只能创建一个聚集索引?

php - 返回 <div> 部分中先前显示的内容

php - 我需要为mysql上的表行增量设置外键吗

php - 我在这里遇到错误,所以帮助我

python - 向 mysql 插入数组值会引发错误

mysql - MySQL 5.0语句中like子句的使用方法

php - 如何使用 PHP 从输入框中删除引号?